Back to Projects
Distributed Systems
Last updated June 2026Distributed Key-Value Store
Fault-tolerant distributed key-value store with consistent hashing, replication, and crash recovery
Overview
A single-node key-value store loses both data and availability the moment that node goes down, and naive sharding creates hot spots as nodes join or leave a cluster.
A 5-node Java/Spring Boot cluster that exposes PUT, GET, and DELETE over a REST API. Keys are placed on a consistent-hash ring (5 virtual nodes per physical node) and replicated to a configurable number of nodes, so reads and writes keep working when individual nodes fail.
Architecture
Client
REST API
Consistent Hash Ring (5 nodes)
Primary + Replicas (RF = 3)
WAL + Snapshot
Engineering Challenges
- Even key distribution as nodes join or leave — solved with virtual nodes (5 per physical node) on the hash ring instead of one point per node, which avoids hot spots.
- Durability across crashes without a full embedded database — every PUT/DELETE is written and flushed to a write-ahead log before being applied in memory, with periodic snapshots (every 30s) to bound WAL growth and speed up recovery.
- Being honest about primary-node failure — the primary is a statically configured coordinator, not a Raft-elected leader, so writes fail fast with a 503 when it's down instead of silently succeeding without real consensus.
Design Decisions
- Configured primary over full Raft/Multi-Paxos leader election: enough to demonstrate replication and failure handling without the log-compaction and split-brain complexity a production system would need.
- Write-ahead log plus periodic snapshots over a full embedded database, trading some read performance for simple, auditable recovery semantics.
Reliability & Scalability
- Replication factor of 3: each write propagates from the primary to the next two nodes on the ring.
- Reads keep succeeding from surviving replicas when other nodes are down; writes fail explicitly (503) if the primary is unreachable rather than silently dropping data.
- A built-in failure-simulation endpoint lets you take a node down on demand and verify recovery behavior end-to-end.
Technology
Java 17
Spring Boot
Docker Compose
Maven
JUnit