client → server · request 1 of 2
The request "hello1" is sent as a 4-byte length, 06 00 00 00 in little-endian order, followed by 6 payload bytes.
Sends two requests, hello1 and hello2, split into random TCP segments, and replays how the server reads them.
roadmap
5/10 done
- Socket programming (done)
- TCP server + client (done)
- Binary protocol + framing (done)
- Concurrent I/O models (done)
- Event loop (done)
- Key-value server (planned)
- Hashtable (planned)
- Sorted set + AVL tree (planned)
- TTL expiry + timers (planned)
- Thread pool (planned)
~/redis-cpp · Systems · ongoing
Redis-style server
A Redis-style TCP server in C++, built from first principles to understand how Redis really works.
- TCP server and client written directly against POSIX sockets.
- Length-prefixed binary protocol (4-byte header + payload) to frame messages over a TCP byte stream.
- read_full / write_all loops so partial reads and writes never corrupt a message, with a 4 KB size guard.
- Event loop over non-blocking sockets, so one thread serves many clients at once.
- Benchmarked 25K requests per second, with 38 µs median and 82 µs p99 latency, over 100K loopback round trips.
what I learned
TCP delivers a byte stream, not messages: one read() can return half a request or two of them, so the protocol has to carry its own boundaries. The event loop changed the shape of the server: instead of blocking on one client at a time, one thread watches every socket and serves whichever is ready, so a slow client no longer holds up the rest.
C++ · POSIX sockets · Jul 2026 – present