Handle a Cache Stampede
A popular cache key expires and overwhelms the database. Design protections for hot keys, concurrent refresh, and cache failures.
Examples
Compare approaches
Baseline approach
Begin by explaining the core mechanism, stating assumptions, and walking through one concrete example.
Time: Depends on design · Space: Depends on design
// Sketch request coalescing and stale-while-revalidate.
Strong answer
Use per-key request coalescing, jittered TTLs, stale-while-revalidate, and bounded refresh concurrency. Define correctness rules before serving stale data.
Time: Discuss operation costs · Space: Discuss retained state
// Sketch request coalescing and stale-while-revalidate.
Common traps
- A distributed lock needs an expiry and safe ownership checks.
- State assumptions and justify trade-offs rather than memorizing a single answer.