0
0
HLDsystem_design~20 mins

Cache stampede prevention in HLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache Stampede Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary cause of a cache stampede?

Imagine many users request the same data at the same time, but the cache for that data has expired. What causes a cache stampede in this scenario?

AThe database is down and cannot respond to any requests.
BThe cache server crashes due to overload from unrelated requests.
CMultiple requests simultaneously miss the cache and all try to fetch data from the database at once.
DThe cache data is corrupted and cannot be read by any request.
Attempts:
2 left
💡 Hint

Think about what happens when many requests try to get data that is not in the cache.

Architecture
intermediate
2:00remaining
Which design best prevents cache stampede by allowing only one request to refresh the cache?

Choose the architecture pattern that ensures only one request fetches fresh data from the database while others wait for the cache to be updated.

ADisable caching entirely to avoid stale data.
BUse a distributed lock or mutex around cache refresh operations.
CAllow all requests to fetch data from the database simultaneously.
DUse a random delay before each request tries to refresh the cache.
Attempts:
2 left
💡 Hint

Think about how to coordinate requests so only one updates the cache at a time.

scaling
advanced
2:00remaining
How does 'early recomputation' help in cache stampede prevention?

Consider a cache system that refreshes data before it expires. What is the main benefit of this approach?

AIt reduces the chance that many requests find the cache expired simultaneously.
BIt increases the cache expiration time to avoid frequent refreshes.
CIt disables caching for high-traffic data to prevent stale reads.
DIt forces all requests to bypass the cache and go to the database.
Attempts:
2 left
💡 Hint

Think about how refreshing cache early affects request timing.

tradeoff
advanced
2:00remaining
What is a tradeoff when using 'request coalescing' to prevent cache stampede?

Request coalescing groups multiple requests for the same data to a single database fetch. What is a downside of this approach?

AIt can increase latency for some requests waiting for the first to complete.
BIt causes the cache to expire more quickly than normal.
CIt requires disabling the cache for all requests.
DIt duplicates database queries for each request.
Attempts:
2 left
💡 Hint

Consider what happens to requests that wait for others to finish fetching data.

estimation
expert
2:00remaining
Estimate the maximum database load during a cache stampede for 10,000 simultaneous requests with no prevention.

If 10,000 users request the same expired cache key at the same time, and each cache miss triggers one database query, what is the maximum number of database queries generated?

A1 query
B1,000 queries
C100 queries
D10,000 queries
Attempts:
2 left
💡 Hint

Think about how many requests miss the cache and query the database simultaneously.