A popular cache key expires and your database suddenly gets hammered by a flood of concurrent requests all trying to recompute the same value. What is this, and how do you prevent it?

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Assesses whether the candidate recognizes the cache stampede / thundering herd problem and can compare concrete mitigations (locking/single-flight, probabilistic early refresh, TTL jitter) with their trade-offs.

What to say

What to avoid

Example answers

Strong: That's a cache stampede: a hot key expires and every concurrent request misses and recomputes at once. I'd coalesce them with a single-flight lock (Redis SET NX with a short TTL) so one request recomputes while the rest serve the stale value or briefly wait, add TTL jitter so keys don't expire in lockstep, and consider probabilistic early refresh so it's renewed just before expiry. I'd confirm the fix on origin QPS and hit-rate dashboards.

Weak: The cache entry expired so everyone hit the DB. I'd set a much longer TTL so it expires less often, and if that's not enough we can add a bigger Redis instance to take more load off the database.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.