Raft consensus lab
A cluster of three to seven nodes elects a leader and replicates a log. Crash nodes, cut the network, submit writes, and watch terms, votes and commit indexes keep the log consistent.
term 0leader nonecommitted 0 entriesmajority 3 of 50 messages in flight
voted nobody, timer 360 ms
- empty log
voted nobody, timer 480 ms
- empty log
voted nobody, timer 470 ms
- empty log
voted nobody, timer 580 ms
- empty log
voted nobody, timer 390 ms
- empty log
Solid cell: committed. Dashed: in the log but not committed. Colour of the border: the term the entry was written in. Grey card: cut off by the partition.
- elections
- 0
- split votes
- 0
- writes committed
- 0 / 0
- writes with no leader
- 0
What just happened
Waiting for the first election timeout.
Waiting for data. Press play or step the simulation.
| Series | Latest | Lowest | Highest |
|---|---|---|---|
| committed entries | no data | no data | no data |
| term | no data | no data | no data |
| Node | State | Term | Voted for | Log length | Commit index | Last entries (write:term) |
|---|---|---|---|---|---|---|
| n0 | follower | 0 | nobody | 0 | 0 | empty |
| n1 | follower | 0 | nobody | 0 | 0 | empty |
| n2 | follower | 0 | nobody | 0 | 0 | empty |
| n3 | follower | 0 | nobody | 0 | 0 | empty |
| n4 | follower | 0 | nobody | 0 | 0 | empty |
Term 0, leader none, 0 committed entries, 0 elections of which 0 split, 0 of 0 writes committed.
What to try
Each one sets up a starting point. Then make the change it describes.
Watch an election
Press Reset and watch the first few seconds with the defaults. Read the event list.
Look for. All nodes start as followers with no leader. The first node whose random timer fires becomes a candidate, asks for votes, and wins when a majority grants them. Then its heartbeats keep everyone else a follower.
Crash the leader
Wait for a leader, then press Crash on its card.
Look for. Heartbeats stop. After an election timeout a follower runs for the next term and wins. Writes submitted while there was no leader are dropped, so a client has to retry. Restart the old node and watch it accept the new leader and its log.
Split votes
Set the election timeout to 150 ms and the network delay to 100 ms, then crash the leader a few times.
Look for. When timeouts are close to the message delay, two nodes often run for the same term and split the vote. Nobody wins that term, both time out again, and the split vote counter climbs. Longer timeouts relative to the delay make this rare.
A leader in the minority
Wait for a leader and a few committed entries, then press Cut the leader into a minority. Submit a few writes while the partition holds.
Look for. The old leader keeps appending to its own log, shown as dashed cells, but its commit index never moves because it cannot reach a majority. The other side elects a new leader in a higher term and keeps committing. Two leaders, but only one can commit.
Heal and repair
With the partition from the previous experiment in place, press Heal the network.
Look for. The old leader hears a higher term and steps down. Its uncommitted dashed entries conflict with the new leader’s log, so they are deleted and replaced. Every log converges to the leader’s, and nothing that was committed is lost.
New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.
Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms