A cache stampede (also called dogpiling) occurs when a heavily requested cached item expires or is evicted and many concurrent requests all miss the cache together. Each one tries to regenerate the value, so the origin suddenly receives far more work than it normally sees.
Why it matters
Caches exist to protect slow backends. During a stampede that protection disappears for a moment, and a query that takes 2 seconds to compute may run hundreds of times in parallel. The database slows down, which makes the rebuilds slower, which keeps more requests missing the cache.
Example
A homepage fragment is cached for 300 seconds and gets 500 requests per second. At the instant it expires, up to 500 requests per second all find it missing. Defenses include:
- Request coalescing or locking: the first request rebuilds the value while others wait or serve the old copy.
- Early recomputation: refresh the entry shortly before it expires.
- Randomized TTLs: add jitter so many keys do not expire together.
- Serving stale: use stale-while-revalidate so users get the old copy while one refresh runs.
Common mistakes
- Giving every cache key the same TTL and warming them all at the same time.
- Purging the whole cache during peak traffic.
- Adding a lock with no timeout, so a crashed rebuilder blocks everyone.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.