Build Redis From Scratch with Java

Series

Build Redis From Scratch

Thirteen parts, from an empty Maven project to a server that speaks RESP, persists to disk, and replicates to a second instance, plus a reference of every link they lean on. Java, no libraries.

  • 14 parts
  • 12.9 hours total
  • beginner to intermediate to advanced
  • Java · Maven · Sockets

Getting started

1 part
  1. Getting set upA Maven project that compiles, runs, and is committed to git. about 30 minutes, mostly downloads beginner

The wire

4 parts
  1. TCP before RedisA server that listens on port 6379, accepts clients, and echoes back whatever they send. about 45 minutes beginner
  2. One read is not one requestFraming that splits a byte stream into requests, then a server that handles many clients at once. about 40 minutes beginner
  3. What redis-cli actually sendsA RESP parser, a RESP writer, and the project's first tests. about 60 minutes intermediate
  4. Bytes become commandsA command dispatcher, plus PING and ECHO. about 30 minutes intermediate

A database, and time

3 parts
  1. A database, and timeThe key-value store, SET, GET, and key expiry. about 60 minutes intermediate
  2. Atomic or wrongEXISTS, DEL, TYPE, KEYS, the INCR family, and lists. about 70 minutes intermediate
  3. Waiting and pretendingBLPOP, MULTI with EXEC and DISCARD, and WATCH. about 70 minutes intermediate

Beyond key and value

3 parts
  1. The server speaks firstPub/sub, streams, and a blocking XREAD. about 80 minutes intermediate
  2. Four more typesHashes, sets, sorted sets, and SCAN. about 70 minutes advanced
  3. The commands that make it usableCONFIG GET, INFO, DBSIZE, FLUSHALL, command line options, the TTL family, and the rest of the string API. about 50 minutes advanced

Durability and replication

2 parts
  1. Surviving a restartAn RDB reader and writer, plus SAVE and BGSAVE. about 80 minutes advanced
  2. Two serversReplication. A second instance that follows the first. about 90 minutes advanced

Reference

1 part
  1. ResourcesEvery link the series leans on, grouped by the part that uses it. a reference, not a read beginner