The Desi Architect
Notes / Docker Sandboxes / Redis Cache-Aside Pattern, Invalidation & Memory Eviction
Docker Sandboxes · Tier 1: Building Blocks · Lab 14

Redis Cache-Aside Pattern, Invalidation & Memory Eviction

Put a cache in front of a slow database and watch it work. See a hit beat a miss, delete the key on write, catch the stale read that DEL still allows, spread TTLs with jitter, survive a stampede, see what Redis deletes when it is full, and see what happens when Redis is down.

Time40 minutes
StackRedis 7Ports 16405, 18085
MemoryAbout 50 MB
Before thisLab 06Redis Basics
Verified runWindows, Mac, LinuxBash and PowerShell
  1. 1PrepareWhat you will learn
  2. 2PredictGuess before you run
  3. 3RunStep by step
  4. 4ObserveWhat you should see
  5. 5Break itChange one thing
  6. 6Clean upLeave nothing running
On this page
  1. 00 / What You Will Learn
  2. 01 / Why It Matters
  3. 02 / What We Are Building
  4. 03 / Words You Need
  5. 04 / Predict First
  6. 05 / Step by Step
  7. 06 / What You Should See
  8. 07 / Look Inside
  9. 08 / Break It, Fix It
  10. 09 / In Real Projects
  11. 10 / Interview Corner
  12. 11 / Clean Up

00 /What You Will Learn

By the end you will be able to
  • Explain cache-aside and the difference between a hit and a miss.
  • Say why you delete the key on write, and show the stale read that still gets through.
  • Explain TTL and jitter, and what a stampede is and how one lock per key stops it.
  • Compare volatile-lru and noeviction when Redis is full.
  • Say what your app should do when Redis is down.

Before you start

Finish Lab 06 (Redis Basics) first. You should know GET, SET, SETEX, DEL and TTL. Docker Desktop must be running.