Each test is 5 questions with varying difficulty.
AI Prep covers AI Agents, Generative AI, ML Fundamentals, NLP & LLMs and a lot more, with adaptive tests and daily challenges. Fully offline on Android. Free to try, one-time unlock for lifetime access.
Cache Penetration and Cache Stampede are critical failure modes in high-scale distributed systems. Cache Penetration occurs when requests for non-existent keys bypass the cache and overwhelm the database, while Cache Stampede (or Thundering Herd) happens when a popular cache key expires, causing a surge of concurrent requests to recompute the data simultaneously. In 2026, as microservices and AI-driven applications rely heavily on low-latency data access, these phenomena are common points of failure in production environments. Roles such as Backend Engineers, SREs, and System Architects are frequently tested on these concepts to evaluate their ability to design resilient, fault-tolerant architectures. Junior candidates are expected to understand the basic mechanics and simple mitigation strategies like null-caching. Senior candidates must demonstrate deep knowledge of advanced synchronization, probabilistic data structures, and the trade-offs between consistency and availability when implementing complex locking or pre-computation strategies.
Understanding these failure modes is the difference between a system that handles traffic spikes gracefully and one that suffers cascading failures. In production, a cache stampede can lead to a 'death spiral' where the database becomes unresponsive, causing latency to spike, which in turn causes more requests to queue up, eventually exhausting thread pools or connection limits. For example, a major e-commerce platform might see a 10x traffic spike during a flash sale; if the cache key for product metadata expires, the resulting stampede could take down the primary database, impacting all services. These topics are high-signal interview questions because they reveal whether a candidate thinks about system state under stress rather than just happy-path CRUD operations. In 2026, with the rise of LLM-based applications where prompt caching and vector search results are frequently cached, the cost of cache misses has increased significantly. A strong answer demonstrates an understanding of how to trade off strict consistency for system stability, showing maturity in handling distributed state.
The cache-database interaction model involves a request flow that must be protected against surges. When a request arrives, the system checks the cache. If it misses, it must decide whether to query the database directly or wait for a lock. The architecture relies on a gatekeeper mechanism to prevent the thundering herd.
Client Request
↓
[Cache Layer]
↓ ↓
[Miss] [Hit] → Return Data
↓
[Bloom Filter]
↓ (If not in set)
[Return 404]
↓ (If in set)
[Distributed Lock]
↓
[Primary Database]
↓
[Update Cache] → Return Data
Store a placeholder (null or empty string) in the cache for keys that do not exist in the database with a short TTL.
Trade-offs: Reduces database load but increases cache memory usage for non-existent keys.
On a cache miss, attempt to acquire a distributed lock. If successful, query the database and update the cache. If failed, wait and retry cache.
Trade-offs: Ensures database safety but introduces latency for the waiting threads.
Calculate a random expiration time or recompute before the actual expiry to stagger the load.
Trade-offs: Reduces stampede risk without locking but may result in slightly stale data.
| Reliability | Use distributed locks with TTLs to prevent deadlocks; implement circuit breakers on the database layer. |
| Scalability | Use consistent hashing for cache partitioning and Bloom filters to reduce DB load. |
| Performance | Minimize lock contention by using probabilistic recomputation; prioritize cache hits. |
| Cost | Bloom filters reduce database query costs; cache nulls increase memory usage. |
| Security | Prevent cache penetration attacks by validating input keys before querying. |
| Monitoring | Monitor cache miss rates, DB CPU usage, and lock acquisition latency. |
Cache penetration occurs when requests for non-existent keys bypass the cache and hit the database. Cache stampede occurs when many concurrent requests for an existing, but expired, key hit the database simultaneously because the cache is empty.
No. Bloom filters are designed to prevent cache penetration by identifying non-existent keys. They do not help with stampede, which involves valid but expired keys.
Not always. For low-traffic keys, the impact of a stampede is negligible. For high-traffic keys, locking or probabilistic recomputation is essential to prevent database collapse.
It is a synonym for cache stampede, where a large number of processes 'herd' to the database at the same time to recompute the same expired cache value.
Jitter adds random time to the TTL. This ensures that keys do not all expire at the exact same moment, spreading the recomputation load over a wider time window.
It is a trade-off. Using a small amount of memory to cache 'null' prevents potentially expensive database queries for non-existent keys, which is a much higher cost in terms of system stability.
Yes. It can lead to serving slightly stale data because the cache is updated before the actual expiry time, based on a probability function.
No. A local mutex only locks threads within a single application instance. In a distributed system with multiple instances, each instance would still perform its own database query.
The system will treat the key as 'possibly present' and query the database. This is safe, as the database will correctly return a 404, but it results in an unnecessary database lookup.
Use locking if strict consistency is required during recomputation. Use probabilistic recomputation if system availability and low latency are higher priorities than serving the absolute latest data.
AI Prep covers AI Agents, Generative AI, ML Fundamentals, NLP & LLMs and a lot more, with adaptive tests and daily challenges. Fully offline on Android. Free to try, one-time unlock for lifetime access.