Course contentsShow
← System Design
Lesson 159 of 1,9194. Caching StrategiesFree lesson

Cache Stampede Problem

The thundering herd effect when many requests simultaneously try to regenerate an expired cache entry.

Cache Stampede Problem

What you'll learn: How a sudden rush of requests to regenerate an expired cache can overload your system.

The Thundering Herd Effect

Imagine a popular cache entry (like a product page viewed by thousands) expires at midnight. At 12:00:01 AM, hundreds of requests arrive simultaneously. Since the cache is empty, all of them race to query the database and regenerate the same cached value. Your database suddenly faces a massive spike—like a stampede of buffalo charging at once.

This is the cache stampede problem (also called the "thundering herd"). When many clients discover a cache miss at the same time, they all try to regenerate the data simultaneously, overwhelming your backend systems.

Why It Happens

Cache entries expire after their TTL (Time-To-Live) runs out. If the entry is popular, many requests arrive before the first one can finish regenerating the cache. Without coordination, every request thinks it needs to do the work.

The Impact

  • Database overload: Sudden spike in identical queries
  • Increased latency: All requests wait for slow database responses
  • Wasted resources: Redundant work computing the same result hundreds of times
  • Potential cascading failure: Backend systems may crash under load

Simple Analogy

Think of a coffee shop with one pot of coffee. When it runs out, if every customer simultaneously rushes to the back to make a new pot, chaos ensues. Better if the first person locks the coffee station, makes a fresh pot, then everyone else gets served.

Key Takeaway:
The cache stampede problem occurs when multiple requests simultaneously try to regenerate an expired cache entry, potentially overwhelming backend systems with redundant identical queries.