Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

Three failure patterns are often grouped together as cache problems: requests for keys that do not exist, a large part of the cache disappearing at once, and a single very hot key expiring under heavy load.

Explain cache penetration, cache avalanche and hot-key breakdown, and give the standard defences against each.

Cache penetration is a stream of requests for data that does not exist, which always miss and reach the database; we defend with input validation, caching not-found results briefly, a Bloom filter of existing ids and rate limits. Cache avalanche is a large part of the cache disappearing at once, through synchronized TTLs, a cluster outage or a cold start, and we defend with TTL jitter, replicated caches, warm-up, concurrency limits and serving stale data. Hot-key breakdown is one very popular key expiring under heavy load, and we defend with request coalescing or a lock, refresh-ahead, or no expiry with background refresh.

Why this question is asked

A cache only protects the database while it answers most requests. These three patterns are the classic ways that protection fails, and interviewers ask about them together because they look alike in a graph, the database suddenly gets too much traffic, but have different causes and different cures. In this answer, we will recap the read path where each problem enters, then take penetration, avalanche and hot-key breakdown in turn with their defences, and finish with a comparison.

1A Quick Recap of the Read Path

Most application caches use cache-aside: the service looks in the cache first, and on a miss it reads the database and stores the result. The database is sized for the traffic left after the cache, perhaps 5 percent of reads at a 95 percent hit ratio. So anything that makes many requests miss at once multiplies the database load.

Each pattern makes requests miss in a different way. Penetration misses because there is nothing to cache. Avalanche misses because many entries are gone at once. Hot-key breakdown misses because one entry is gone while thousands of requests want it.

2Cache Penetration: Asking for What Does Not Exist

If a client asks for product 99999999 and it does not exist, the cache has nothing to store, so a plain cache-aside implementation goes to the database every time. A scraper or attacker enumerating random ids can therefore send all of its traffic straight to the database, bypassing a cache with a perfect hit ratio for real products.

The defences work in layers. Validate ids early, rejecting malformed or out-of-range values before any lookup. Cache not-found results with a short TTL, such as 30 to 60 seconds, so repeated requests for the same missing id stop at the cache. Keep a Bloom filter of existing ids: a compact bit array that answers either definitely not present or possibly present, so most unknown ids are rejected without a query. And rate limit clients that produce many misses.

Java
BloomFilter<Long> ids = BloomFilter.create(Funnels.longFunnel(), 10_000_000, 0.01); // Guava, about 12 MB
productIds.forEach(ids::put); // load existing ids; add new ones on create
ids.mightContain(5001L); // true: possibly present, check cache then database
ids.mightContain(99_999_999L); // false: definitely absent, return 404 at once

A Bloom filter never says no for an id that exists, but it says maybe for about 1 percent of absent ids at the size chosen here, and those few fall through to the cache and database as before. It cannot remove entries easily, so deleted products remain possibly present until the filter is rebuilt.

3Cache Avalanche: Losing Much of the Cache at Once

An avalanche is when a large share of entries becomes unavailable together. The causes are a batch of entries written together with the same TTL and expiring together, a cache cluster outage, or a cold start, such as a deploy that changes key formats or a new cache node starting empty. The database then receives a large fraction of all reads in the same moment, often many times what it can handle.

The defences address each cause. TTL jitter spreads expiry times. Replicated cache clusters across availability zones keep one node or zone failure from emptying the cache. Warm-up loads the most-requested keys before a new cache or service takes full traffic. And because some avalanches will happen anyway, the database needs protection of its own: concurrency limits and circuit breakers on the database calls, so excess requests fail fast or receive stale data where that is acceptable, instead of piling onto the database.

4Hot-Key Breakdown: One Popular Key Expires

Some keys are far hotter than others, such as the homepage configuration or a viral product, read thousands of times per second. When such a key expires, every request in the next moment misses, and if each of them rebuilds the value, the database receives thousands of identical queries for one row or one expensive aggregation.

The defences make sure only one caller rebuilds, or that nobody has to. Request coalescing (Caffeine's get with a loader within a JVM, or a short distributed lock across pods) lets one caller rebuild while others wait briefly or use the old value. Refresh-ahead reloads the value before it expires, for example with refreshAfterWrite, so readers keep getting a value. And for the very hottest keys, we can store them without expiry and refresh them from a background job, so they never disappear from the cache at all.

Three problems, three causes
ProblemWhy requests missMain defences
PenetrationThe data does not existValidation, not-found caching, Bloom filter
AvalancheMany entries gone at onceTTL jitter, replicas, warm-up, limits
Hot-key breakdownOne hot entry expiredCoalescing, refresh-ahead, no expiry
All three end the same way, with the database receiving traffic it was never sized for.

5Telling Them Apart in Production

The symptoms overlap, so the metrics must separate them. Penetration shows as misses that find nothing in the database, a rising 404 rate, often from a small set of clients. An avalanche shows as a sudden drop in the hit ratio across many keys, often right after a deploy, a cache failover or a round hour. Hot-key breakdown shows as a spike of identical queries for one key, visible in per-key metrics or in the database's top queries. Recording hits, misses that found data and misses that found nothing as separate counters makes the first diagnosis take seconds.

6Follow-up questions

Which of the three is hardest to test for, and how would you do it?

Avalanche, because it needs realistic scale: a full keyspace, real access patterns and enough traffic to show what the database does when most of the cache is gone. Penetration and hot keys can be tested with a focused load test. For avalanche, the honest test is a game day: replay production traffic in a staging environment, or in a single production cell, empty the cache, and measure how the database, load shedding and warm-up behave and how long recovery takes.

Can caching not-found results cause problems?

Yes. If a product is created right after its id was cached as not found, it appears missing until the short TTL ends. The create path should delete the not-found entry, and the TTL should be short. Not-found caching also needs a size limit, because an attacker can fill the cache with random ids.

Is a Bloom filter needed if we already cache not-found results?

Not always. Not-found caching stops repeated requests for the same missing id, but an attacker who uses a new random id each time defeats it. The Bloom filter stops those as well, so it is worth adding when enumeration with fresh ids is a real risk.

7Conclusion

In this answer, we saw that penetration is traffic for data that does not exist, defended by validation, short-lived not-found caching, a Bloom filter and rate limits; avalanche is losing a large part of the cache at once, defended by TTL jitter, replicated clusters, warm-up and database-side limits and stale serving; and hot-key breakdown is one popular key expiring under load, defended by coalescing or a lock, refresh-ahead or background refresh without expiry. Separate metrics for hits, found misses and empty misses tell them apart.

What to say in the interviewAbout 90 seconds aloud

Open with

All three send traffic to the database that the cache was supposed to absorb, but for different reasons. Penetration is requests for data that does not exist, often random or invalid ids from scrapers or enumeration.

Then, if they want more

Nothing gets cached, so every request reaches the database. I defend against it by validating ids early, caching not-found results with a short TTL like 30 seconds, using a Bloom filter of existing ids so unknown ids are rejected without a query, and rate limiting clients with many misses.

Avalanche is when a large part of the cache disappears at once: TTLs that were set together expire together, the cache cluster fails, or a deploy starts with a cold or differently keyed cache.

Defences are TTL jitter, replicated multi-zone clusters, warming up before taking traffic, and protecting the database itself with concurrency limits and circuit breakers, serving stale data where that is acceptable. Hot-key breakdown is a single very popular key expiring, so thousands of concurrent requests rebuild it at once.

There I make sure only one caller rebuilds, with request coalescing or a short lock, refresh it ahead of expiry, or keep the hottest keys without expiry and refresh them in the background. To tell them apart I track hits, misses that found data and misses that found nothing separately.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain cache penetration, cache avalanche and hot-key breakdown, and give the standard...": https://scrivio-interview-library.netlify.app/architecture/caching-strategies/5dceb6a1fb/