Cache Penetration, Cache Breakdown, and Cache Avalanche: Concepts and Solutions
The article explains the concepts of cache penetration, cache breakdown, and cache avalanche in Redis‑based systems, analyzes the performance problems they cause under high concurrency, and presents practical mitigation techniques such as Bloom filters, caching empty objects, distributed locks, high‑availability clusters, rate limiting, and data pre‑warming.
Cache Penetration
Concept
When a user queries data, the system first checks Redis; if the key is missing, it queries the persistent database. If the database also has no record, the request fails. Under high concurrency, many such misses cause a large number of database queries, putting pressure on the backend and possibly causing a crash. This situation is called cache penetration.
Solutions
1. Bloom Filter
A Bloom filter is a probabilistic data structure that stores all possible query parameters as hashes. The request is first validated against the filter; if it does not match, the request is discarded, preventing unnecessary database queries.
2. Cache Empty Objects
When the storage layer does not hit, even an empty object is cached with an expiration time, so subsequent requests retrieve the empty placeholder from the cache, protecting the backend data source.
However, this method has two drawbacks:
Storing many empty values consumes additional cache space.
Even with expiration, there can be a window of inconsistency between cache and storage, affecting consistency‑critical business.
Cache Breakdown
Concept
Cache breakdown differs from cache penetration. It occurs when a hot key expires and a massive concurrent request bypasses the cache, directly hitting the database. The sudden surge of queries can overwhelm the database.
Solutions
1. Keep Hot Data Never Expire
By not setting an expiration time for hot keys, the cache never becomes a bottleneck when the key would otherwise expire.
2. Add Mutual Exclusion Lock
Use a distributed lock to ensure that only one thread queries the backend for a given key while others wait, shifting the concurrency pressure to the lock mechanism.
Cache Avalanche
Concept
A cache avalanche happens when a large number of cached items expire simultaneously, causing a massive influx of requests to the database and potentially crashing it. It can also be triggered by a cache node failure, which creates an unpredictable surge of traffic to the database.
Solutions
1. Redis High Availability
Deploy multiple Redis instances in a cluster so that if one node fails, others continue to serve requests.
2. Rate Limiting and Degradation
After cache expiration, control the number of threads that read from the database and write back to the cache using locks or queues, allowing only one thread per key to perform the operation.
3. Data Pre‑warming
Before a major traffic event, proactively access likely hot data to load it into the cache and stagger expiration times to avoid simultaneous expiry.
看完本文有收获?点赞、分享是最大的支持!
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
