All projects

04Systems & simulation

C++ Key-Value Store

A Redis-inspired TCP server with a worker pool, key expiry and crash recovery through an append-only, CRC-checked write-ahead log.

  • C++20
  • TCP
  • CMake
  • Docker
Terminal session issuing SET, GET and EXPIRE beside a write-ahead log

Inside the server

A TCP accept loop hands connections to a worker pool. The store uses a shared mutex so reads can run in parallel, and an expiry sweeper removes stale keys in the background.

The server logs mutations before acknowledging them. On restart it replays complete, CRC-checked records and truncates a partial tail so new writes can continue.

Try the protocol

After starting the server, connect with kvcli and run commands from the interactive prompt.

kv> SET project systems
OK
kv> EXPIRE project 300
1
kv> GET project
"systems"

Durability

  • Append-only write-ahead log, flushed before each acknowledgement
  • CRC per record, so torn writes are detected on replay
  • Partial tail truncated on boot instead of refusing to start

Testing & benchmarks

The test suite covers command parsing, expiration, TCP sessions and recovery after the server is killed. A benchmark client reports throughput and latency under a mixed read/write workload.