A Raft consensus simulator
Several computers, one identical list.
Large services do not keep their data on a single computer — if that one dies, everything is gone. The data lives on several computers at once, and every one of them has to hold exactly the same list of records. The difficulty: any of them can die at any moment, and the network can cut out mid-delivery. Raft is the rulebook that keeps them in agreement anyway.
What you just read is the easy part. The hard part is a handful of small rules in Raft that look redundant — until you switch one off. That is what this app is for: turn a rule off, then watch the guarantee it was defending collapse in front of you.
Where to start
How it works, briefly
One leader is elected
Every computer waits to hear from a leader. Whichever waits longest without hearing anything stands for election and asks for votes. Once more than half vote for it, it is the leader — the only one allowed to record anything new.
Records are copied to everyone
The leader sends each new record to all the others. Once more than half have stored it, it is declared committed: settled, and never to change again.
Stragglers are brought back into line
A computer that was down or cut off gets its list reconciled as soon as it is reachable again. If its list had diverged, the wrong part is overwritten by the leader’s.
- 11
- 21
- 32
- 11
- 21
- 32
- 11
- 21
- 3—
How to read the picture
Each shape is one computer. The little boxes between them are messages in flight — messages take time to arrive, and some never arrive at all.
Leader
In charge. The only one that accepts new records and distributes them.
Follower
An ordinary member. Waits to hear from the leader and copies its records.
Candidate
Currently standing for election and asking the others for their votes.
Down
Currently down. Sends nothing and receives nothing.
Five promises that must never break
Raft promises five things. This app checks all five after every single event — not at the end, but continuously — and names the one that failed the moment it fails.
Election Safety
There are never two leaders at once in the same round.
At most one leader can be elected in a given term.
Leader Append-Only
A leader only ever adds to the end of its list; it never deletes its own records.
A leader never overwrites or deletes entries in its log; it only appends new entries.
Log Matching
If two computers hold the same record at a row, everything above that row is identical too.
If two logs contain an entry with the same index and term, then the logs are identical in all entries up through the given index.
Leader Completeness
A record that has been settled never goes missing from any later leader.
If a log entry is committed in a given term, then that entry will be present in the logs of the leaders for all higher-numbered terms.
State Machine Safety
No two computers ever act on different contents at the same row.
If a server has applied a log entry at a given index to its state machine, no other server will ever apply a different log entry for the same index.
If you already know Raft
A deterministic simulation, an invariant checker that shares no code with the algorithm, Figure 2 implemented rule by rule, and a fuzz suite that gates every deploy.