cloudpatterns.appClassroomKatasWhiteboardBlog
Z3 · Caching & Delivery

Cache stampede

Cache stampede

Gold

When a popular cached item expires, or the whole cache is flushed, many requests miss at once and hit the database together — which can overload it.

Use when
Recognize it whenever hot keys expire together or a cache restarts under load
Avoid when
Low-traffic keys — the herd is too small to matter
Trade-offs
Coalescing adds complexity and makes followers wait · Early refresh spends background work on keys that may not be read
Requires
Cache-aside
2 objectives · 6 misconceptions
  • predict Predict the database load spike when a hot key expires under heavy traffic.
  • choose Choose a mitigation: request coalescing, jittered TTLs or early refresh — or a brake (rate limit, circuit breaker, load shedding) in front of the database.
  • Not true: Giving every key the same TTL is harmless.
  • Not true: The only fix is a bigger database.
  • Not true: Restarting the overwhelmed database fixes the outage.
  • Not true: A sudden jump in database load means more users arrived.
  • Not true: A stampede happens only when a hot key's TTL runs out.
  • Not true: Making requests wait for one shared fetch stalls them all, so coalescing swaps an overloaded database for a site that hangs.

Stories here

Neighborhood

builds onCache-aside
Cache stampede
unlocksnothing yet
contrast withHot keys
On linesCache Line

Progress is saved on this device