"What are cache penetration, cache breakdown, and cache avalanche? How do you handle them?"
These three scenarios are the archetypal cache failure modes and come up in nearly every backend interview. They test your ability to anticipate attack patterns and load spikes — whether you've designed a cache for real traffic or just read a tutorial.
Define each precisely — penetration: queries for data that does not exist in either cache or DB, so the cache never fills and every query hits the DB. Breakdown: a single hot key expires and thousands of concurrent requests stampede the DB. Avalanche: many keys expire at the same time (or Redis itself goes down) and the DB is flooded.
For penetration: cache the null result with a short TTL, or put a Bloom filter in front of the cache to reject known-nonexistent keys before even hitting Redis.
For breakdown: use a mutex lock (SETNX) so only one thread rebuilds the cache while others wait or return stale data; or mark hot keys as "logically never expire" and rebuild asynchronously in the background.
For avalanche: jitter the TTL (base TTL + random offset) so keys don't expire in lockstep; add a multi-level cache (local Caffeine + Redis); enable circuit breaker and rate limiter on the DB path; run Redis with HA (sentinel or cluster) so the cache layer doesn't disappear entirely.
Tie it together: production systems combine multiple defenses — Bloom filter + null caching for penetration, mutex for hot-key breakdown, TTL jitter plus local cache plus circuit breaker for avalanche.
These are three distinct failure modes. Cache penetration is when requests query keys that exist in neither the cache nor the database — for example, an attacker hitting /user/-1 repeatedly. The cache never gets populated so every request hits the DB. Two defenses: cache the null result with a short TTL (say 60s) so repeated attacks are absorbed by Redis, and put a Bloom filter in front — on startup or on write, add every valid ID to the filter, and reject queries that miss the filter. Bloom filters have false positives but never false negatives, so they're safe for this use case. Cache breakdown is different — the data exists, but a single hot key expires, and before anyone can rebuild the cache, thousands of concurrent requests pile up on the DB. The fix is either a mutex — the first request to miss acquires a short-lived Redis lock and rebuilds, everyone else waits or returns stale — or "logical never expire", where the cache never actually expires but carries a logical expiry timestamp inside the value; when it's past logical expiry, one thread asynchronously refreshes while others keep serving the stale data. Cache avalanche is when many keys expire at the same moment, or Redis itself goes down — the DB gets hit by the full read load and often collapses. Defenses are layered: first, jitter TTLs — instead of setting every key to exactly 3600s, use 3600 + random(0, 600), so expirations spread over time. Second, add a local in-process cache (Caffeine in Java, Guava) in front of Redis — even if Redis dies, each JVM serves from its own memory for a minute. Third, put circuit breakers and rate limiters on the DB path so when the DB falls behind, it fails fast instead of piling up connections. Fourth, run Redis with Sentinel or Cluster so a single node failure doesn't drop the whole cache. In production, I combine all of these — Bloom filter + null cache + TTL jitter + local cache + circuit breaker — rather than picking one.
Interviewers often mix the three up — define each one clearly before jumping to solutions.
Mentioning Bloom filters and the trade-off of false positives is a strong signal.
For avalanche, "TTL jitter + local cache + circuit breaker" together is the complete answer; one alone isn't enough.
Use HireMe AI in your real interview to make sure you don't swap "breakdown" and "avalanche" under pressure — it happens a lot.
It consumes Redis memory for nonexistent keys. Mitigate with short TTL (60s) and using a compact null marker like an empty string.
Yes — SET mutex:keyname 1 NX PX 30000. First thread gets the lock and rebuilds; others retry after a short sleep.
It helps after a deploy or restart, but doesn't handle mass TTL expiry. Combine warming with TTL jitter.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free