RAFT / KVdistributed systems lab v1.0.0 ↗
Interactive protocol model

Break the leader.
Keep the data.

A visual walkthrough of a persistent three-node key-value store built in Go. Writes complete only after a two-node majority confirms the log entry.

<543msworst measured leader replacement
150ksuccessful benchmark writes
50/50fault scenarios passed
SIMULATION · NOT LIVE TRAFFIC
01LEADER
node-1Term 18 · :8081
healthy
02FOLLOWER
node-2Term 18 · :8082
healthy
03FOLLOWER
node-3Term 18 · :8083
healthy
2 / 3 quorum available
01 / SYSTEM DESIGN

One logical store.
Three independent processes.

Clients can contact any node. Followers redirect writes to the current leader. The leader serializes mutations, replicates log entries, and acknowledges only after a majority has persisted them.

01HTTP clientPUT · GET · status
→
02Leader APIvalidation · deduplication
→
03Raft coreterm · log · commit index
→
04Durable stateatomic write · fsync · rename
API

Client boundary

HTTP endpoints expose writes, linearizable reads, explicitly stale reads, and observable node status.

RPC

Peer boundary

RequestVote, AppendEntries, and InstallSnapshot coordinate nodes over non-persistent HTTP connections.

SSD

Storage boundary

Terms, votes, logs, snapshots, and commit progress survive process and container restarts.

02 / WRITE PATH

What happens after
PUT /kv/color?

The safety guarantee comes from order: persist locally, replicate to peers, reach quorum, then apply and acknowledge.

STEP 1 · CLIENT BOUNDARY

Only the leader accepts a mutation.

A follower returns the known leader so the client can retry. A client/request ID makes that retry idempotent instead of creating a duplicate write.

POST /kv/color
{
  "value": "cyan",
  "client_id": "demo",
  "request_id": "42"
}
DEFAULT

Linearizable read

Leader-only read that confirms current-term authority with a quorum. It never returns an older value after a completed write.

GET /kv/:key
DIAGNOSTIC

Stale replica read

Available from any node without a quorum round trip. Useful for observing replication while explicitly accepting older data.

GET /kv/:key?consistency=stale
RETRY SAFE

Idempotent write

A repeated request ID returns the original result. Reusing that ID for different content is rejected as a conflict.

client_id + request_id
03 / FAILURE ENGINEERING

Fault tolerance is a
tested behavior.

Each scenario begins with fresh containers and volumes, injects one controlled failure, verifies safety during the fault, heals the cluster, and checks deterministic convergence.

15×

Leader process crash

Stop the active leader, elect a replacement, commit through the surviving quorum, restart the old leader, verify catch-up.

PASS
15×

Live network partition

Keep the old leader running but isolated. It must reject quorum-confirmed reads while the majority partition elects and writes.

PASS
10×

Lagging follower

Leave a follower behind the compaction boundary, then require snapshot installation plus log-suffix catch-up.

PASS
10×

Container restart

Recover persisted term, vote, log, snapshot, commit index, key/value state, and deduplication records without reconfiguration.

PASS
INVARIANTA minority may remain available, but it cannot commit.

This prevents split-brain writes: progress requires two of three nodes.

04 / PERSISTENCE + COMPACTION

Bounded history.
Complete recovery.

Snapshots keep the replicated log from growing forever while preserving enough state to reconstruct the service and retry semantics.

SNAPSHOTindex 100KV state + request dedupe
1–100
compacted prefix
101
102
103
104
105

01Leader detects follower's nextIndex is behind the retained log.

02InstallSnapshot transfers the compacted state atomically.

03Normal replication resumes with entries after the snapshot index.

05 / MEASURED EVIDENCE

Claims backed by
repeatable experiments.

Fifteen independent 10,000-write runs used fresh cluster state at concurrency 1, 8, and 16. Every run verified commit index, key count, and a deterministic SHA-256 state hash across all nodes.

TOTAL SUCCESSFUL WRITES150,000
0 failed0 divergent
FAULT MATRIX50/50

100% scenario pass rate

LEADER REPLACEMENT543 ms

maximum observed in matrix

PARTITION HEALING180 ms

maximum observed convergence

Throughput / latency matrixFive 10,000-write repetitions per concurrency level
durable quorum writes
ConcurrencyMean throughputp50 latencyp95 latencyp99 latencyConvergence
1 worker21.52 ops/s45.97 ms86.20 ms106.59 msVerified
8 workers24.99 ops/s325.18 ms576.37 ms609.42 msVerified
16 workers25.50 ops/s625.29 ms1134.82 ms1206.84 msVerified

Why throughput plateaus: the implementation prioritizes understandable safety and synchronous durable writes over batching. Each committed mutation pays persistence and quorum costs—an explicit engineering tradeoff, not a hidden benchmark condition.

06 / PROBLEMS SOLVED

From failure mode
to engineering control.

The project is a collection of safety decisions. Each mechanism exists because a specific distributed-systems failure makes the simpler design incorrect.

PROBLEM

Single-node failure loses availability

↓SOLUTION

Replicated log, randomized elections, heartbeats, and majority-based leadership.

PROBLEM

Two leaders can claim authority

↓SOLUTION

Monotonic terms, one persisted vote per term, and step-down on higher-term messages.

PROBLEM

A retry can apply a write twice

↓SOLUTION

Persisted client/request IDs with same-command replay and conflict rejection.

PROBLEM

Quorum contact alone can allow a stale read

↓SOLUTION

A committed current-term no-op barrier before serving linearizable reads.

PROBLEM

An old leader remains alive after partition

↓SOLUTION

Quorum-confirmed reads and writes; non-persistent peer connections reflect network state.

PROBLEM

Logs grow and slow follower recovery

↓SOLUTION

Automatic snapshots, absolute log indexes, compaction, and InstallSnapshot RPC.

07 / INTERVIEW MODE

Explain the system
from first principles.

Use these prompts to walk through the design. Open any question for a concise answer, then follow the source links for implementation detail.

01Why does a three-node cluster tolerate only one failure?+

A commit needs a majority: two votes or acknowledgements. With one node unavailable, two remain and can progress. With two unavailable, the survivor cannot distinguish failure from partition and must stop committing to preserve safety.

02What happens when the current leader crashes?+

Followers stop receiving heartbeats. After randomized election timeouts, one becomes candidate, increments the term, votes for itself, and requests votes. A candidate with an up-to-date log becomes leader after receiving two votes.

03Why can’t the isolated old leader keep writing?+

It may append locally, but cannot collect a second acknowledgement. Without a majority, it cannot advance the commit index or report success. When connectivity returns, the higher-term leader overwrites any conflicting uncommitted suffix.

04How is a GET made linearizable?+

Reads are leader-only and quorum-confirmed. A newly elected leader first commits an entry from its current term, establishing authority over committed history before it serves the read.

05How does a follower recover after missing compacted entries?+

If the follower's next required index precedes the leader's retained log, the leader sends a snapshot. The follower installs it atomically, restores key/value and deduplication state, then receives the remaining log suffix normally.

06What real bug did fault testing uncover?+

Leaders were still processing their election timers, causing unnecessary term churn during sustained writes. The fix made leaders ignore election timeouts, and a race-enabled regression test now protects that state-machine rule.

OPEN SOURCE · MIT LICENSE

Read the implementation.
Reproduce the evidence.