Build Redis
10 scenes · ~70 min · build the primitive

Build your own Redis

An in-memory data-structure server: one thread, rich types, optional persistence, async replication. Internalize the cost of single-threaded simplicity and a dozen caching/HA decisions get easier.

  1. 01
  2. 02
  3. 03
  4. 04
  5. 05
  6. 05a
  7. 06
  8. 07
  9. 08
  10. 09
  1. 01
    Foundations — what Redis is, words you'll hear
    An in-memory data-structure server, the eight core nouns, and the six canonical types. Orientation before you touch the internals.
    ~7 min
  2. 02
    One thread, one command at a time
    Why a single event loop is fast — and why one slow command (KEYS *, big LRANGE, slow Lua) stalls every client.
    ~7 min
  3. 03
    Encodings flip under you
    Listpack ↔ hashtable, intset ↔ hashtable, embstr ↔ raw — crossing a threshold silently rewrites memory and op-cost.
    ~7 min
  4. 04
    Persistence — fork, CoW, and the 1-second window
    RDB snapshots via fork+CoW, AOF fsync policies, and why default Redis can lose ~1s of writes on crash.
    ~7 min
  5. 05
    Eviction is sampled, not exact
    maxmemory + sampled LRU/LFU — Redis only inspects N keys per pass; tunable via `maxmemory-samples`.
    ~7 min
  6. 05a
    TTL and cleanup — lazy, active, and the freer thread
    Passive + 10Hz active sampler expire keys; DEL of a big value freezes the loop unless `lazyfree-*`/UNLINK offloads to the background freer thread. Cache stampede + jitter / SET NX rebuilder lock.
    ~7 min
  7. 06
    Replication is async — acked writes can vanish
    PSYNC, replication backlog, and the AP-not-CP gotcha: WAIT doesn't fix it; min-replicas-to-write does (at the cost of unavailability).
    ~7 min
  8. 07
    Sentinel — quorum detects, majority elects
    SDOWN/ODOWN ladder, epoch-based election, and the operator footgun: quorum ≠ majority.
    ~7 min
  9. 08
    Cluster — 16384 slots and the client routes
    CRC16 mod 16384, MOVED vs ASK (permanent vs transient), hash tags, configEpoch — and why sharding alone is not HA.
    ~7 min
  10. 09
    Design your Redis deployment
    Capstone: pick persistence, HA, and sharding for a stated SLO; the verifier traces each choice back to the scene that taught it.
    ~7 min