Key Exam Topics for Architects: Cache Penetration, Cache Breakdown, and Cache Avalanche

The article explains how cache penetration, cache breakdown, and cache avalanche all stem from cache layer failures that let requests flood the database, compares their triggers, impact scopes and risk levels, and presents practical mitigation techniques such as empty‑value caching, Bloom filters, mutex locks, logical expiration, TTL randomization, and multi‑level caching.

Subtle Storm
Subtle Storm
Subtle Storm
Key Exam Topics for Architects: Cache Penetration, Cache Breakdown, and Cache Avalanche

Cache Penetration occurs when a request queries data that is absent both in the cache and the database. Because caches only store existing data, each request bypasses the cache and hits the database, quickly exhausting connection pools and potentially crashing the system. Typical malicious examples include queries with IDs like -1 or 999999999. Three mitigation strategies are presented:

Cache empty values with a short TTL (e.g., 5 minutes) to prevent repeated DB hits.

Use a Bloom filter loaded with all valid IDs at startup; if the filter indicates non‑existence, the request is blocked before reaching the cache.

Validate request parameters at the entry layer, combined with rate limiting and authentication.

Cache Breakdown (or cache stampede) happens when a hot key expires under high concurrency, such as during a flash‑sale. The data still exists in the database, but the sudden cache miss causes a massive burst of DB queries. Three solutions are discussed:

Mutex (distributed) lock: only the first request rebuilds the cache while others wait, reducing DB load from thousands of queries to a single one.

Logical expiration: store an expiration timestamp inside the cached value, return stale data if expired, and asynchronously refresh the cache.

Never‑expire hot keys: for super‑hot data, omit TTL and refresh the cache explicitly when the underlying data changes.

Cache Avalanche refers to large‑scale cache failures when many keys expire simultaneously or the cache server crashes, leading to a system‑wide DB overload. It is essentially a massive cache breakdown. Four mitigation approaches are outlined:

TTL randomization: add a random offset (e.g., ±10 minutes) to each key’s TTL to stagger expirations.

Redis high‑availability clusters (master‑slave replication, Sentinel, or Redis Cluster) to survive node failures.

Multi‑level caching: add a local cache in front of Redis so that even if Redis fails, most traffic is served locally.

Service circuit‑breaker and degradation: reject or return fallback data when DB pressure exceeds a threshold.

The article emphasizes that in production environments these techniques are often combined to build a defense‑in‑depth strategy rather than relying on a single solution.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Redisdistributed-lockBloom filtercache avalanchecache breakdowncache penetrationTTL randomization
Subtle Storm
Written by

Subtle Storm

The micro era's marvels are boundlessly subtle.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.