Lesson 9 of 15
13. Caching at Scale

13.8 How do you know your cache is healthy?

3 min read+10 XP

At the wedding: The head cook watches a few things: how often the fridge has what's asked for, how often things are thrown out for space, how full it is, and how long the queue at the shop is getting.

In the system: Watch these, per cluster and per key prefix (Chapter 30):

MetricWhat it tells youWorry when
Hit rate (overall and per prefix)Is the cache doing its job?It drops suddenly (bad deploy changed keys, restart)
Evictions per secondIs it big enough?High evictions together with a falling hit rate
Memory usedRoom to grow?Close to the limit
Latency (p50, p99)Is the cache itself slow?p99 rising: hot key, big values, network
Per-node loadIs load even?One node far busier than others: hot key (13.4)
Database queries per secondWhat the cache is savingJumps while the hit rate falls: stampede or avalanche
Connections, errors, timeoutsCan clients reach it?Rising errors: failover, overload

Redis, for example, reports hits and misses (keyspace_hits, keyspace_misses), evicted keys and memory use in its INFO output.

Alerts worth having: hit rate drops by a large amount in a few minutes; one node's load is several times the average; evictions spike; database queries jump while the cache's hit rate falls.

Memory code: "Watch the hits, the throw-outs, the fullness and the shop's queue."