0
0
Redisquery~20 mins

Cache-aside (lazy loading) deep dive in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cache-aside Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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?
AReturn null immediately without fetching from database
BFetch data from database, store it in cache, then return data
CFetch data from cache again, then return null if not found
DStore null in cache first, then fetch data from database
Attempts:
2 left
💡 Hint
Think about how lazy loading works to reduce database hits.
🧠 Conceptual
intermediate
2: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?
ABecause caching null can cause stale data if the database later has valid data
BBecause Redis does not support storing null values
CBecause caching null values increases memory usage unnecessarily
DBecause null values cause Redis to crash
Attempts:
2 left
💡 Hint
Consider what happens if the database updates after caching null.
📝 Syntax
advanced
2: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
A
GET user:123
IF null THEN fetchUserFromDB()
SET user:123 value
RETURN value
B
SET user:123 value
GET user:123
RETURN value
C
GET user:123
RETURN value
D
DEL user:123
GET user:123
fetchUserFromDB()
RETURN value
Attempts:
2 left
💡 Hint
Remember to fetch from DB only if cache miss occurs.
optimization
advanced
2: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?
ADisable caching and always fetch from DB
BIncrease Redis cache TTL to infinite
CUse distributed locks or mutexes to allow only one DB fetch on cache miss
DUse Redis DEL command frequently to clear cache
Attempts:
2 left
💡 Hint
Think about controlling concurrent access to DB on cache miss.
🔧 Debug
expert
3: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?
ARedis automatically updates cache when database changes
BThe cache TTL is set to zero causing immediate expiration
CThe database update failed silently
DThe application updates the database but does not invalidate or update the cache
Attempts:
2 left
💡 Hint
Think about cache consistency with database updates.