rgoussu@goussu: ~/library/system-design/exercises
~/library/system-design/exercises cat build-your-own-redis.md

Build your own Redis

# Build a RESP-speaking in-memory key-value server — protocol parsing, a deliberately chosen concurrency model, expiry, eviction under a memory cap, and a benchmark to prove it.

Exercisesaved 2026-08-08source #exercise#redis#caching#concurrency#networking#performance

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

Milestones

  1. RESP parser — decode/encode the Redis serialization protocol as a standalone, unit-tested library: simple strings, errors, integers, bulk strings, arrays.
  2. PING/ECHO server — a TCP server answering a single client; redis-cli PING against your port works unmodified.
  3. Concurrent clients — choose a model (event loop, or thread-per-connection over a locked store) and write down why; parallel redis-cli sessions stay correct.
  4. GET/SET with expirySET with EX/PX options, passive expiry on read, then an active expiry sweep so dead keys don't linger.
  5. Eviction under a memory cap — a maxmemory limit with approximate LRU; fill the cache past the cap and verify hot keys survive.
  6. Benchmark & profile — run redis-benchmark against 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