Knowledge Guide
HomeSystem DesignCaching

Cache Stampede & Invalidation — Thundering Herd and the Hard Half

The cache made things worse — all at once

A single hot key (a trending post, a config) is cached and serving thousands of reads per second from memory. Its TTL expires. Now every in-flight request misses simultaneously and they all query the database with the same query at the same instant — a cache stampede (thundering herd). The DB, sized for the cache-hit rate, gets hit by 1000× its expected load and can fall over, taking the service with it.

A hot cache key expires and 1000 concurrent requests all miss and hit the database with identical queries simultaneously
A hot cache key expires and 1000 concurrent requests all miss and hit the database with identical queries simultaneously

Make sure only ONE request rebuilds the key

The other hard half: invalidation

"There are only two hard things in computer science: cache invalidation and naming things." — Phil Karlton

Keeping the cache coherent with the source of truth is the deeper problem. Options trade freshness vs complexity: short TTL (simple, allows staleness), write-through (update cache on write — see Caching strategies), explicit invalidation on change (precise but you must catch every write path, incl. other services), or versioned keys. There's no free lunch — pick the staleness you can tolerate.

Takeaways


Re-authored for this guide; stampede diagram hand-authored as SVG. Follows the Memcached/Redis stampede literature and Cloudflare/Instagram engineering. See also: Caching strategies, Designing for Failure (load shedding), Rate Limiting, (Concurrency) the lost-update race.

🤖 Don't fully get this? Learn it with Claude

Stuck on Cache Stampede & Invalidation — Thundering Herd and the Hard Half? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Cache Stampede & Invalidation — Thundering Herd and the Hard Half** (System Design) and want to truly understand it. Explain Cache Stampede & Invalidation — Thundering Herd and the Hard Half from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Cache Stampede & Invalidation — Thundering Herd and the Hard Half** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Cache Stampede & Invalidation — Thundering Herd and the Hard Half** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Cache Stampede & Invalidation — Thundering Herd and the Hard Half** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes