Backend Development 11 min read

How to Ace Redis Interview Questions: Prevent Cache Avalanche, Penetration, and Breakdown

This article explains Redis cache avalanche, penetration, and breakdown, illustrates real interview scenarios, and provides practical strategies such as random expiration, Bloom filters, and high‑availability setups to help candidates answer these common interview questions confidently.

macrozheng
macrozheng
macrozheng
How to Ace Redis Interview Questions: Prevent Cache Avalanche, Penetration, and Breakdown

Preface

Redis is ubiquitous in backend development, and interviewers often probe deeply into its usage and principles. The author, motivated by personal interview experiences, writes a series to help readers tackle Redis‑related questions and secure offers.

Main Content

When discussing Redis , most interviewees are familiar with cache avalanche , penetration , and breakdown . These terms describe different failure modes of caching systems.

Interview Starts

A middle‑aged interviewer asks about Redis cache avalanche.

Example of cache avalanche: If all homepage keys expire at the same time (e.g., 12 hours), a sudden traffic spike (6 000 requests per second) can overwhelm the database because the cache is empty, leading to a system crash.

To mitigate avalanche, assign each key a random extra expiration time when setting it:

<code>setRedis(Key, value, time + Math.random() * 10000);</code>

If using a Redis cluster, distribute hot data across multiple nodes to avoid simultaneous expiration. Alternatively, keep hot data without expiration and refresh it only on updates.

Cache Penetration vs. Breakdown

Cache penetration occurs when requests query keys that do not exist in both cache and database (e.g., negative IDs). Attackers can exploit this to overload the database.

Mitigation includes input validation at the API layer (e.g., reject IDs ≤ 0) and using a Bloom filter to quickly check key existence before hitting the database.

Cache breakdown resembles avalanche but focuses on a single hot key. When that key expires, a flood of requests bypasses the cache and hits the database, potentially causing a crash.

Solutions: set hot keys to never expire, or use a mutex lock to ensure only one request repopulates the cache.

Additional Defensive Measures

Beyond expiration strategies, employ high‑availability setups such as Redis master‑slave replication, Sentinel, or Redis Cluster to prevent total failure. Use local caches (e.g., Ehcache) with circuit‑breaker tools like Hystrix to protect downstream databases. Persist Redis data with RDB and AOF for fast recovery after restarts.

Conclusion

Understanding how cache avalanche, penetration, and breakdown happen, how to prevent them, and how to recover from them is essential for backend interviews. Demonstrating clear thinking and practical solutions will impress interviewers and increase the chance of receiving an offer.

High AvailabilityRedisCache AvalancheCache BreakdownCache PenetrationBackend Interview
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login 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.