Exercises
Explore practical caching techniques used in backend systems with Redis. This quiz assesses cache-aside, write-through and write-behind patterns, TTL behavior, eviction policies, key design, negative caching, invalidation across services, hot-key mitigation, and safe distributed locking. Questions range from foundational concepts to production scenarios involving stale data, cache stampedes, and consistency trade-offs.
Answer the questions below and check the explanation for each answer.
0/17 answered
Auto audio on: the next questions will be read aloud when you click Continue.
In cache-aside, the application reads the cache first. After a miss, it loads the value from the database and places that value in the cache for later requests.
A TTL defines how long a key may remain available. After the duration expires, Redis can remove the key, limiting how long stale cached data persists.
user:42:profile uses a predictable namespace, resource identifier, and data type. This reduces collisions and makes related keys easier to inspect or invalidate.
The key expires at approximately 12:01:00. A lookup five seconds later should not obtain the cached value and must be handled as a cache miss.
Jitter spreads expiration times across a range. This reduces synchronized misses that could suddenly send a large wave of requests to the database.
Least Recently Used eviction removes the entry that has gone unused for the longest time. Because A has the oldest access, it is the eviction candidate.
Negative caching temporarily records a not-found result. It can protect the database from repeated requests for the same missing resource, usually with a short TTL.
A cache stampede occurs when many requests simultaneously miss a popular key and regenerate it, potentially overwhelming the database or downstream service.
A per-key lock lets one worker regenerate the value while equivalent requests are coalesced, delayed, or served stale data. This limits duplicate backend work.
SET with NX and expiration atomically creates the lock only if it does not exist and gives it a timeout, reducing race conditions and abandoned locks.
Broadcast invalidation distributes an update or deletion event so that all instances can remove affected local entries rather than continuing to serve stale copies.
After the database update succeeds, invalidating the related key forces the next reader to reload current data. Deleting is often safer than trying to reconstruct every cached representation.
Write-through updates the cache and persistent store as part of the write path. This keeps cached data current but adds work and latency to writes.
Write-behind acknowledges the cache update before asynchronously persisting it. It can improve write latency, but failures require careful durability and recovery handling.
The key must represent inputs that affect the result, such as page, page size, filters, sorting, locale, or tenant. Otherwise one request may receive another variant's data.
A hot key concentrates requests on the shard that owns it. Replication for reads, local caching, request coalescing, or carefully splitting the workload can reduce the bottleneck.
The owner must compare its unique token and delete the key atomically, commonly with a script. Unconditional deletion could remove a newer lock acquired after the original lock expired.
Video Courses
Advanced
Ideal for beginners
recommended
Thousands of online courses in video, ebooks and audiobooks.
To test your knowledge during online courses
Generated directly from your cell phone's photo gallery and sent to your email
Download our app via QR Code or the links below:.
+ 10 million
students
Free and Valid
Certificate
60 thousand free
exercises
4.8/5 rating in
app stores
Free courses in
video and ebooks