Redis & Caching
Put a number on the cache
Everyone can say what a cache is for. Almost nobody can say what theirs costs. This is the arithmetic: how many queries this minute of traffic sends, which key the policy takes when memory runs out, how many keys one edit has to reach, and how many identical queries one expiry lets through.
- Modules
- 5
- Drills
- 10
- Build steps
- 3
- Time
- ~4h
Walk out able to
Read a key scheme, a policy and a minute of traffic you have never seen, write down four integers, and say which line of the design produced each one.
What you drill
The shape the access wants
Structures, and what a session actually returns.
Lifetimes and eviction
What TTL says, and which key the policy takes.
Wiring and invalidation
Store touches per pattern, and the race that survives.
Stampedes
What one expiry costs, and what each fix saves.
The pitch
What you practise, and what you leave with
A reflex for costing a cache in integers, plus your own Redis session — a keyspace you filled and an eviction you caused on purpose.
You will practise
- Structures, commands and what they return
- Expiry semantics and eviction policy
- Store touches per access pattern
- Invalidation races and stampede cost
Afterwards you can
- Count what a pattern costs the database
- Name the key an eviction policy takes
- Count the keys one change has to reach
- Cost a stampede and each mitigation
Modules
5 modules, 24 items
Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.
- 1
Pick the shape
~36 minChoose the structure an access makes cheap, and read a session without guessing.
- LessonWhy count a cache4 min
- LessonChoose the shape before the key12 min
- DrillMatch the structure to the access10 min
- DrillSay what the session prints10 min
- 2
Give it a life
~35 minSay what TTL returns after any sequence, and which key the policy takes next.
- LessonWatch the cache run out of room13 min
- DrillDecide what TTL says10 min
- DrillName the key that goes12 min
- 3
Wire it to the store
~48 minCount what a pattern costs the database, and pick the wiring a constraint forces.
- LessonFollow one value through the wiring6 min
- LessonWhat a write does to the copy5 min
- LessonWhat write-through buys back5 min
- LessonWhat write-around costs you4 min
- LessonWhat the count cannot see4 min
- DrillCount the store touches14 min
- DrillPick the wiring the constraint forces10 min
- 4
Delete the right key
~36 minRead an interleaving, and count the keys one change has to reach.
- LessonDelete in the right order13 min
- DrillRead the interleaving12 min
- DrillCount the keys one change reaches11 min
- 5
Survive the expiry
~1hCost a stampede and each fix, on a real server and then on a cold system.
- LessonSee the herd arrive11 min
- DrillCount what one expiry costs12 min
- DrillCount the rebuilds serving stale buys12 min
- Build stepStart a real Redis6 min
- Build stepCause an eviction on purpose8 min
- Build stepWatch an overwrite kill a TTL4 min
- LessonCost the front page20 min
More in Data & databases
Keep going
SQL: Queries
Say what a query returns before you run it.
Intermediate~3h6 modules
ORMs
Count the queries before the mapper sends them.
Intermediate~4h6 modules
SQL: Joins & NULL
The rows that found no partner, and the values that are not there.
Advanced~4h5 modules
SQL: Advanced
The clause you did not write decided the number.
Advanced~6h7 modules
Every cache is a number you chose.
The first item is free. ~4h of focused work, at your own pace.
Intermediate~4h5 modules