Skip to content

Build Redis from Scratch

Build a fully functional Redis clone from the ground up. You'll implement the RESP protocol, key-value storage, expiry, lists, hashes, sets, sorted sets, and transactions — all through test-driven exercises. By the end, you'll deeply understand how one of the world's most popular databases works internally.

advanced29 lessons8 chapters29 graded exercisesPython

No sign-up needed for lesson 1 · certificate on completion · sign up to save progress

What you’ll have built

Chapter by chapter. Every step is a graded exercise.

  • RESP Protocol Fundamentals
  • String Commands
  • Key Expiry
  • Lists
  • Hashes
  • Sets & Sorted Sets
  • Advanced Features
  • Scripting, Replication & Streams
Starts in Python — solve in the language you choose in the editor, same tests either way.

Curriculum

8 chapters, 29 lessons. Each lesson is a short read, one graded exercise, and a quiz.

  1. 1PING — Your First Redis CommandRead · exercise · quiz
  2. 2ECHO — Returning DataRead · exercise · quiz
  3. 3The RESP Wire FormatRead · exercise · quiz
  4. 4Error HandlingRead · exercise · quiz
  5. 5RESP Array Parsing — The Real Wire ProtocolRead · exercise · quiz
Loading reference solution…
Going further

When the tests are green, keep going.

Read

  • Redis in Action (Josiah Carlson) — the canonical book on Redis usage patterns and internals.
  • The Redis source code itself: src/server.c, src/object.c, src/networking.c. ~50k lines but very readable.
  • The RESP3 spec at redis.io/docs/reference/protocol-spec for the wire format.

Build next

  • Persistence: implement RDB snapshotting (fork + serialize) and AOF (append-only file). About 200 more lines.
  • Pub/sub: a fan-out channel system. ~100 lines on top of the existing dispatcher.
  • Transactions (MULTI/EXEC/DISCARD/WATCH): per-connection command queue with optimistic concurrency.
  • Cluster mode: hash slot assignment, MOVED/ASK redirects, gossip-based topology. This becomes a 1k-line project.

Continue with our courses

  • Build Kafka — Redis is great at fast in-memory state; Kafka is great at durable ordered logs. Different shape, same kind of work.
  • Build a Distributed KV Store (Raft) — when one Redis isn't enough, you replicate. Raft is how.