Cache stampede: when a cold cache floods the database
A cache stampede happens when a cache suddenly stops answering most reads — after a restart, a flush or a mass expiry — and every miss goes straight to the database at once.
What causes it
A warm cache with a 90% hit ratio sends only 10% of reads to the database. Empty it and the database receives ten times its normal read traffic instantly — often far beyond its capacity. Connections fill up, latency explodes, and the cache cannot warm up because the database is too slow to answer the misses.
How to recognise it
- Hit ratio dropping to near zero
- Database “too many connections” right after a cache restart or deploy
- Recovery taking far longer than the restart itself
The math
Database load = λ_read × (1 − hit ratio) + λ_write
How to fix it
- Warm the cache before sending traffic
- Use request coalescing so one miss loads each key
- Make sure the database can survive a cold cache
Reproduce it in the simulator
These templates trigger this failure on purpose:
Learn more
Part of the guide Caching in system design.
