Challenge - 5 Problems
Cache-aside Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Cache miss handling in cache-aside pattern
In a cache-aside pattern using Redis, when a cache miss occurs, what is the correct sequence of actions to retrieve and cache the data?
Attempts:
2 left
💡 Hint
Think about how lazy loading works to reduce database hits.
✗ Incorrect
In cache-aside, on a cache miss, the application fetches data from the database, stores it in the cache, then returns it. This avoids repeated database hits for the same data.
🧠 Conceptual
intermediate2:00remaining
Why avoid caching null values in cache-aside?
In cache-aside pattern, why is it generally discouraged to cache null or empty results directly?
Attempts:
2 left
💡 Hint
Consider what happens if the database updates after caching null.
✗ Incorrect
Caching null means the cache will serve empty results even if the database later has valid data, causing stale cache issues.
📝 Syntax
advanced2:30remaining
Correct Redis command sequence for cache-aside get
Which Redis command sequence correctly implements a cache-aside get operation for key 'user:123' assuming a database fetch function fetchUserFromDB()?
Redis
Pseudocode: 1. Try to get value from Redis 2. If not found, fetch from DB 3. Store in Redis 4. Return value
Attempts:
2 left
💡 Hint
Remember to fetch from DB only if cache miss occurs.
✗ Incorrect
The correct flow is to GET from Redis, if null then fetch from DB, SET in Redis, then return.
❓ optimization
advanced2:30remaining
Reducing cache stampede in cache-aside pattern
What is an effective technique to reduce cache stampede (many requests causing DB overload) in cache-aside pattern with Redis?
Attempts:
2 left
💡 Hint
Think about controlling concurrent access to DB on cache miss.
✗ Incorrect
Using distributed locks ensures only one request fetches from DB and others wait, preventing overload.
🔧 Debug
expert3:00remaining
Diagnosing stale data in cache-aside pattern
You notice your Redis cache returns outdated user profile data even after the database was updated. Which of the following is the most likely cause?
Attempts:
2 left
💡 Hint
Think about cache consistency with database updates.
✗ Incorrect
Cache-aside requires explicit cache invalidation or update after DB changes; otherwise stale data remains.