skip to content
arjun nair
projects
completed

distributed key-value store

C++ · completed

why I built it

I wanted one project where networking, storage, concurrency, replication, and failure handling all had to work together. A key-value store is a good excuse: the interface is tiny (GET, SET), so all the difficulty lives underneath it.

architecture

Clients connect over the network to a leader node, which applies writes and replicates them to followers. If the leader fails, a follower takes over and clients are redirected.

Primary server and replicas connect with replication, failover, and storage.
Conceptual replication layout from the supplied image. The storage block represents intended persistence work, not a finished storage engine.

networking

The client/server layer handles connections, framing requests and responses, and keeping many clients in flight at once. It's the first place performance and correctness collide — a slow or misbehaving connection shouldn't stall everyone else.

replication + leader/follower

Replicated state means every write has to reach followers before it's safe to rely on. The leader orders writes, followers apply them in the same order, and the system has to agree on who the leader is — the core of leader/follower behavior.

Client write passes to the primary and replicas, followed by an acknowledgment and response.
Conceptual write sequence from the supplied image, not a recorded request trace.

failure recovery

The interesting part was what happens when the leader disappears. Followers detect the failure, one is promoted, and clients reconnect. In the measured failover test, that took about 202 ms, with zero failed requests.

storage

I also worked toward a page-backed storage layer with Insert, Get, Delete, and Update operations, exploring how persistent storage engines organize data on disk. That layer was work toward a storage engine rather than a finished one.

benchmarking + results

Under the load I tested, the system handled about 5,700 writes per second with 22 ms average latency and 42 ms p99 latency. A leader failover took about 202 ms, and no requests failed during that test. Replication on the write path accounts for much of the latency.

what I learned

Most of the design work ended up being about failure behavior rather than GET and SET. It was useful to measure what happened when the leader disappeared instead of only testing the normal request path.

arjun nair · stanford