A sharded key-value store in C++20. I wrote Raft myself from the paper, then built a harness to see if it actually holds up.
A five-node cluster running in your browser. Kill the leader and watch the rest elect a new one.
Loading the cluster…
Three node processes talk gRPC over localhost, elect a leader, and copy every write to each follower's disk. The client library finds the leader on its own, follows redirects, retries safely, and gives linearizable reads.
Acknowledged writes survive the leader being killed with a real SIGKILL. A script writes ten keys through the command line, kills the leader process, and reads them all back.
There are no performance numbers yet because I haven't benchmarked it. When there are, each one will link to the raw output of a script in the repo.
A client hashes a key onto a consistent hash ring to find its shard, then talks to that shard's Raft group directly, with no coordinator hop. Each group is an independent Raft instance with its own log, and one node process hosts several groups.
A write goes through consensus, and once it commits it's applied to that node's LSM engine. The part I like most is the boundary between the two: one narrow interface, so the Raft code knows nothing about how bytes reach a disk.
Applying a command doesn't fsync
The obvious design fsyncs storage on every apply, so each write costs two fsyncs: one for the Raft log, one for storage. But apply only needs the write and the applied index to land together, not to be durable. They go into one write batch, so a crash keeps both or neither, and Raft's own log can replay anything that got lost. The catch is a rule I have to keep: never compact the Raft log past what storage has safely persisted.
Commands carry a client id and a sequence number
If a leader dies mid-request the client retries, and without dedup the write gets applied twice. So the state machine keeps a table of each client's last sequence number and result, saved in the same batch as the write and included in every snapshot. Skip this and a system can pass all its own tests, then fail a linearizability checker.
Only current-term entries commit by counting replicas
This is the Figure 8 case from the Raft paper, and from-scratch implementations often get it wrong. If a leader commits an old-term entry just because a majority has it, a later leader with a different history can overwrite it. Old entries only count as committed once a current-term entry above them commits.
The Raft core has no threads, no sockets and no clock. Time only moves when I call Tick(), so a whole five-node cluster runs inside a single unit test and every run is fully determined by its seed.
The harness delays, reorders, drops and duplicates messages, splits the cluster into groups, and kills and restarts nodes with only what they had saved to disk. It checks all five Raft safety properties after every single step instead of at the end, so a violation shows up right where it happens. Any failing seed replays exactly.
In total that's 200 tests, clean under ASan, UBSan and TSan, plus 2,000 randomized fault scenarios.
A follower fixed its log correctly, then reverted after a restart. I was deciding what to save by comparing log lengths. When a follower cuts off a conflicting tail and refills it in the same step, the log is the same length with different entries, so nothing got written, and the old entries came back after a crash.
It only showed up hundreds of steps later, on a node that looked completely healthy.
Here's what it can't do yet.
I add to this list as I find things, and I don't remove anything until it's actually fixed.