Deep Dive
high level designdistributed systemsconsensus

Raft, Driven: Watch a Cluster Elect, Replicate, and Heal

Everyone can recite 'Raft elects a leader by majority.' The hard part is the log — how a follower that missed writes during a partition gets repaired, and the one subtle rule that stops a committed entry from ever being lost. Drive a live 5-node cluster, then take it apart.

·20 min read
Hard

Most explanations of Raft stop at the election: a node times out, asks for votes, wins a majority, done. That’s the famous part — and it’s the easy part. The part that actually keeps your data correct is what happens to the log afterward: how a follower that was asleep, slow, or partitioned during three writes gets caught up without anyone reading stale data, and the single non-obvious rule that guarantees a committed entry survives every future election.

So before any prose, take the controls. This is a real 5-node Raft cluster — elect a leader, write to it, replicate, then break it: crash the leader mid-flight, or split the network 3-against-2 and watch which side keeps working.

Click a node to crash or revive it. Bars are log entries, coloured by the term that created them; a filled underline marks committed entries.

ClusterN = 5 · majority = 3
Leader— none —
Committed0
What just happened
  • Fresh cluster — every node is a follower in term 0.

Three things to try

  • Elect → write → replicate. Notice a write is uncommitted (dim bar) until a majority stores it, then it commits (solid underline). Commit is a majority ack, not a unanimous one.
  • Crash the leader after a write. The cluster stalls until you trigger a new election — and the new leader is always one that already has the committed entry. That’s not luck; it’s the vote rule.
  • Split the network 3 | 2. The 3-side keeps committing. The 2-side can start elections forever and never win one. A minority that can’t act is Raft working correctly — the alternative is split-brain.

Why the log is the whole story

writeAppendEntriesAppendEntries✗ (later)Clientwrite x=7Leaderappend → log[n]Followerlog matches ✓ → appendFollowerlog diverged → repair, then appendFollowerpartitioned → catches up later
A leader's log is the source of truth; followers converge to a byte-identical copy of it. The consistency check on every AppendEntries is what makes 'converge' safe rather than hopeful — a follower only accepts new entries if its log agrees with the leader's up to the point right before them.

The election picks who writes. Everything that makes Raft safe — that a committed entry is never lost, that two nodes never disagree about entry number five — lives in how the log is replicated, checked, and committed. The election is a few hundred milliseconds of drama; the log is forever.

The members-only deep-dive is the mechanism, end to end: the Log Matching Property and the AppendEntries consistency check that enforces it; how a leader repairs a divergent follower by backing up and overwriting its tail; the deceptively subtle commit rule (why a leader may not commit an entry from a previous term by counting replicas — the Raft “Figure 8” hazard) with the exact guard that fixes it; the Leader Completeness and State Machine Safety properties that tie it together; cluster membership changes without a moment of two-leader risk; how etcd, CockroachDB, TiKV, and MongoDB run this in production (including how they serve linearizable reads without a disk write); and an interview challenge with a worked answer.

Members only

Keep reading with Premium

You've reached the members-only part of this deep-dive — the full implementation, the interactive ring simulator, and the step-by-step walkthrough. Unlock it with a membership.

Related Articles