Cache Stampede
Also known as: dogpile effect, cache miss storm
A cache stampede occurs when a popular cache entry expires and every concurrent request for it misses simultaneously, sending the full uncached load to the origin at once. The origin is sized for the cache hit rate, so a single expiry on a hot key can saturate it.
Last reviewed · Part of the Architecture Glossary
In practice
Do the arithmetic once and the risk stops being abstract. A homepage query runs at 2,000 req/s with a 99% hit rate — the database sees 20 req/s and the query takes 400 ms. The entry expires. For the 400 ms it takes to recompute, every arriving request misses: 800 concurrent identical queries against a pool of 50 connections. The pool exhausts, unrelated queries queue behind it, and the outage looks like a database problem.
Three mitigations, roughly in order of preference:
- Coalescing / mutex. The first miss takes a lock and recomputes; the rest wait for the result. One origin query instead of 800.
- Probabilistic early expiry. Recompute before the TTL with a probability that rises as expiry approaches (
XFetch). Refresh happens while the old value is still serving. - Stale-while-revalidate. Serve the expired value and refresh in the background. Correct only where slightly stale data is acceptable — which is most read paths, if you ask honestly.
When it matters
Any high-traffic key with an expensive origin: homepage feeds, pricing tables, permission sets, rendered fragments, embedding lookups.
Common mistake
Setting the same TTL for every key populated by the same warm-up job. They then expire in the same second, and the stampede hits every key at once. Add ±10% jitter to every TTL.
See also
- Thundering HerdA thundering herd is a surge of simultaneous requests to one resource, triggered by an event that releases many waiting clients at once — a cache expiry, a service restart, a synchronised retry, a cron.
- BackpressureBackpressure is the mechanism by which an overloaded component signals upstream to slow down, rather than accepting work it cannot complete.
- Hot PartitionA hot partition is a single shard receiving a disproportionate share of traffic, so it saturates while the rest of the cluster idles.