An asyncio-based Redis clone covering the parts that make Redis a distributed system, not just a hash map: the protocol, the persistence format, and the replication handshake.
Implemented
- RESP protocol parser (RESP2). Hand-rolled byte-level parsing of bulk strings, arrays, integers, and simple strings; written so the parser stays correct when data arrives in arbitrary TCP fragments.
- Commands: PING, ECHO, GET, SET (with PX expiry stored as Unix timestamps), CONFIG GET, INFO replication.
- RDB parsing: opcode-by-opcode decoder of the RDB binary format on startup, so the server warm-starts from disk.
- Single-leader replication: replica side initiates the full handshake —
PING → REPLCONF listening-port → REPLCONF capa → PSYNC ? -1. Master responds with+FULLRESYNC <replid> <offset>and ships its RDB. After that, the master forwards every write command to all connected replicas.
What was hard
The replication handshake is one of those things where every step looks obvious until you write the master side and find your timing is wrong. Specifically: the master has to send the FULLRESYNC response and then immediately start streaming the RDB bytes; if the replica is reading the response in 100-byte chunks and isn’t ready for binary data, the protocol desyncs subtly.
(Codecrafters challenge — protocol work is real, the framework structure follows their guided path.)