The Desi Architect
Notes / Browser demos / Cache Stampede: The Thundering Herd Problem
Interactive demo Free

Cache Stampede: The Thundering Herd Problem

Try the model, then compare what changed. This is a browser simulation with illustrative inputs.

Illustrative simulation. The values come from a model, not a measured production system.
Interactive Lab · Cache Protection

When the Redis cache key for the IPL Final score expires at 10:00 PM, 500 concurrent users hit refresh at the same second. Compare Naive Cache-Aside vs Single-Flight Mutex to see how to prevent database collapse.

Guided Walkthrough: What to do and what to watch

  1. Step 1 (The Outage): Select "Naive Cache-Aside" and click "Slam 500 Readers (Key Expired)".
    What you will see: All 500 requests bypass the expired cache. The PostgreSQL card turns red and vibrates with a 100% CPU OVERLOAD alert. The connection pool maxes out at 100/100, and 340+ requests fail with HTTP 504 Gateway Timeout.
  2. Step 2 (The Solution): Switch to "Single-Flight Mutex" and click "Slam 500 Readers" again.
    What you will see: The API Gateway card turns blue (holding a group mutex). 499 requests await one promise in memory while exactly 1 query queries PostgreSQL. DB CPU stays at 8%, and all 500 requests resolve in 42ms with 0 errors!
  3. Step 3 (Warm Cache Hit): Click "Warm Up Cache".
    What you will see: Redis turns emerald green (HIT). P99 latency drops to 0.8 ms, completely bypassing the database.

500 Readers

Clients
Idle

API Gateway

Concurrency Control
Pass-through

Redis Cache

Key: ipl:score
TTL: EXPIRED

PostgreSQL

Source of Truth
Idle (2% CPU)
Database CPU Load 2%
DB Active Conns 2 / 100
P99 Response Time 1.8 ms
Failed Requests 0 (0%)
Learn the idea behind it

The demo shows what breaks. The lesson explains why it breaks, and what you give up with each fix.

This demo is free. The System Design pass (₹499) opens all 28 demos, 36 design interview problems and 75 Docker labs. See what the pass includes →

Read the related guide