All labs
Lab 40
Caching Strategies

Cache Stampede & Stale-While-Revalidate

A hot key's TTL expires and thousands of requests miss at once, stampeding the origin — the thundering herd. Watch the origin spike, then tame it with a single-flight lock, jittered TTLs, and stale-while-revalidate that serves slightly old data while one request refreshes.

A hot key (SkyTravel's "Delhi → Mumbai" results) just expired and 20 requests arrive at once. Watch how many actually reach the origin under each strategy.
20 concurrent requests
waiting…
key expired
🗄️ Origin load0 calls
Bonus — jitter the TTLs. If 10,000 keys are all cached with exactly a 60s TTL, they expire on the same tick and stampede together. Add a small random offset (say 60s ± 10%) and expiries spread out, so the origin never faces a synchronized wall of misses.
What just happened