RedisIntermediate~4h

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

01

The shape the access wants

Structures, and what a session actually returns.

02

Lifetimes and eviction

What TTL says, and which key the policy takes.

03

Wiring and invalidation

Store touches per pattern, and the race that survives.

04

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. 1

    Pick the shape

    ~36 min

    Choose 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. 2

    Give it a life

    ~35 min

    Say 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. 3

    Wire it to the store

    ~48 min

    Count 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. 4

    Delete the right key

    ~36 min

    Read 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. 5

    Survive the expiry

    ~1h

    Cost 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

Every cache is a number you chose.

The first item is free. ~4h of focused work, at your own pace.

Intermediate~4h5 modules