Penetration, Breakdown, & Snowslide

Difficulty: Advanced

Question

Explain cache penetration, cache breakdown and cache avalanche (snowslide). How would you prevent each one?

Answer

All three are ways a cache stops protecting the database. Cache penetration is repeated requests for data that does not exist anywhere, so every request misses the cache and hits the DB. Cache breakdown (hotspot invalid) is a single very hot key expiring and thousands of concurrent requests rebuilding it at once. Cache avalanche (snowslide) is a large number of keys expiring together, or the cache going down entirely, sending a wave of traffic to the DB.

Cache penetration: lookups for keys that never exist

Typical cause: bots or bugs requesting product:999999999, or an attacker iterating IDs. The DB returns nothing, the app caches nothing, and the next request repeats it.

  • Cache null results: store a sentinel like "__NULL__" with a short TTL (30-60 seconds).
  • Bloom filter in front: keep all valid IDs in a Bloom filter (BF.ADD, BF.EXISTS, built into Redis 8 and earlier available via RedisBloom). If the filter says "definitely not present", reject without touching the DB. False positives are possible, false negatives are not.
  • Validate input at the API layer (ID format, ranges) and rate limit abusive clients.

Cache breakdown: one hot key expires

Typical cause: the homepage banner or a flash-sale product during Big Billion Days expires, and 10,000 requests miss within the same millisecond.

  • Mutex / single flight: the first miss takes a lock with SET lock:key token NX PX 5000 and rebuilds; others wait briefly and retry the cache, or serve a stale copy.
  • Logical expiry: store the value with an embedded expiresAt but no Redis TTL. When a reader sees it is logically expired, it triggers an async refresh and returns the old value.
  • Proactive refresh: refresh known hot keys before they expire, or never expire them and update on write.

Cache avalanche: many keys or the whole cache fail

Typical cause: a warm-up job loads 1 million keys with the same EX 3600, so they all expire at the same minute. Or a Redis node crashes.

  • TTL jitter: EX 3600 + random(0, 600) spreads expiry over time.
  • High availability: replicas with Sentinel or Cluster so one node failure is not total cache loss.
  • Circuit breakers and rate limiting on DB calls, plus graceful degradation (serve defaults).
  • Multi-level caching: a small in-process cache (Caffeine, node-lru-cache) absorbs bursts.

Quick comparison

ProblemKeys involvedRoot causePrimary fix
PenetrationNon-existent keysNothing to cacheCache nulls, Bloom filter
BreakdownOne hot keyConcurrent rebuild on expiryMutex or logical expiry
AvalancheMany keys or whole cacheSynchronised expiry or outageTTL jitter, HA, circuit breaker

The terms "breakdown" and "snowslide" are common in Chinese-origin interview material; in Western writing you will also hear "cache stampede" or "thundering herd" for breakdown and "cache avalanche" for snowslide.

Three ways a cache stops protecting the DB. Each failure mode has a different trigger and therefore a different fix.
PenetrationBreakdownAvalanche
TriggerRequests for missing dataOne hot key expiresMass expiry or cache down
ScopeMany unknown keysSingle keyMany keys
First fixCache null valuesRebuild under a lockRandom TTL jitter
Second fixBloom filterLogical expiryReplicas and circuit breaker

Code examples

Read path handling all three problems (Node.js, node-redis v4+)

const NULL = '__NULL__';
const ttl = (base) => base + Math.floor(Math.random() * 300); // jitter

async function getProduct(id) {
  if (!(await redis.bf.exists('bf:products', id))) return null; // penetration

  const key = `product:${id}`;
  const cached = await redis.get(key);
  if (cached === NULL) return null;
  if (cached) return JSON.parse(cached);

  // breakdown: only one caller rebuilds the key
  const got = await redis.set(`lock:${key}`, '1', { NX: true, PX: 5000 });
  if (!got) {
    await new Promise((r) => setTimeout(r, 50));
    return getProduct(id); // retry; add a max-retries guard in real code
  }
  try {
    const row = await db.products.findById(id);
    await redis.set(key, row ? JSON.stringify(row) : NULL,
      { EX: row ? ttl(3600) : 60 }); // avalanche: jittered TTL
    return row;
  } finally {
    await redis.del(`lock:${key}`);
  }
}

The Bloom filter blocks unknown IDs, null results are cached briefly, a short lock prevents a stampede on rebuild, and random TTLs keep keys from expiring together.

Key points

  • Penetration: missing data bypasses cache; fix with null caching and Bloom filters.
  • Breakdown: one hot key expires; fix with a rebuild lock or logical expiry.
  • Avalanche: mass expiry or cache outage; fix with TTL jitter, HA and circuit breakers.
  • Bloom filters give no false negatives, only false positives.
  • Redis 8 includes Bloom filter commands (BF.*) in the open source server.

Common follow-up questions

  • How does a Bloom filter work and how do you size it?
  • What happens if the process holding the rebuild lock crashes?
  • How would you warm the cache after a full Redis restart?
  • How does request coalescing (single flight) differ from a distributed lock?

Interview tips

  • Define all three crisply before discussing fixes; candidates often mix up breakdown and avalanche.
  • Give at least two mitigations per problem and mention their trade-offs (null caching uses memory, locks add latency).
  • Anchor with a flash sale or IPL final scenario to make the answer concrete.

Concepts covered

Cache Penetration, Cache Breakdown, Cache Avalanche, Bloom Filter, TTL Jitter, Mutex Lock

More Redis & Caching questions