Goal
Build an in-memory key-value server that real Redis clients can talk to — RESP protocol in, cache semantics out — then make it correct under concurrent clients and bounded in memory. Proves you can carry a wire protocol, a concurrency model, and eviction from paper to a benchmarked, profiled server.
Subject: full brief & instructions
Practices
- Cache management — TTL expiry, eviction policies, and what actually determines the hit rate.
- Concurrency and Parallelism — event loop vs. thread-per-connection, and keeping shared state honest.
- Performance engineering — benchmark honestly, profile, fix the widest tower, measure again.
- System design fundamentals — one of the core building blocks, built instead of drawn.
Milestones
- RESP parser — decode/encode the Redis serialization protocol as a standalone, unit-tested library: simple strings, errors, integers, bulk strings, arrays.
- PING/ECHO server — a TCP server answering a single client;
redis-cli PINGagainst your port works unmodified. - Concurrent clients — choose a model (event loop, or thread-per-connection over a
locked store) and write down why; parallel
redis-clisessions stay correct. - GET/SET with expiry —
SETwithEX/PXoptions, passive expiry on read, then an active expiry sweep so dead keys don't linger. - Eviction under a memory cap — a
maxmemorylimit with approximate LRU; fill the cache past the cap and verify hot keys survive. - Benchmark & profile — run
redis-benchmarkagainst it, flame-graph the hot path, fix the biggest cost, and report before/after numbers.
Stretch goals
- More commands:
INCR, lists (LPUSH/RPUSH/LRANGE), hashes. - Persistence: an append-only file replayed on startup.
- Pub/sub:
SUBSCRIBE/PUBLISH— fan-out without persistence, the opposite corner from a durable log (message brokers & event streaming). - Compare your throughput with real Redis on the same box and explain the gap.
- Continue with CodeCrafters' staged version (codecrafters.io) for guided extensions such as replication.
Related
- Build your own Redis — subject — the self-contained work statement: RESP2 wire format, command set, expiry/eviction semantics, benchmark protocol.
- Cache management — cites this exercise from its Practice list.
- Concurrency and Parallelism — likewise; the concurrency-model decision is milestone 3.
- Message brokers & event streaming — the pub/sub stretch goal crosses into its territory.
- Build a load balancer & rate limiter — kin exercise: another edge box built from scratch.