What is a Cache Stampede and How to Prevent It?
Cache stampede (or dogpile effect) is when a cached item expires and many requests hit the backend simultaneously to rebuild it, causing overload.
When to Use
This issue arises in high-traffic systems where many users request the same popular item. Preventing it is critical in scenarios like news feeds, e-commerce product pages, or real-time analytics.
Example
If a cached weather update expires at noon, thousands of users refreshing at that time will all query the database at once—leading to a spike and possible crash.
For deeper learning, check out Grokking System Design Fundamentals, Grokking the System Design Interview, or practice with Mock Interviews with ex-FAANG engineers to prepare like a pro.
Why Is It Important
A stampede can take down even well-architected systems under load. Solving it ensures stability, resilience, and consistent performance.
Interview Tips
Define it clearly, explain the risk, then suggest fixes: locking (one request refreshes while others wait), stale-while-revalidate, or jittered expirations. This shows both conceptual and practical mastery.
Trade-offs
Prevention methods often sacrifice freshness or simplicity for stability. For instance, serving stale data ensures reliability but may temporarily show outdated info.
Pitfalls
Common mistakes include ignoring staggered expirations, overusing locks (risking deadlocks), or refreshing too many cache keys simultaneously.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78