Raft election simulator
Raft keeps a cluster of servers agreeing on one leader. Time is cut into terms. In each term a node either wins the election and leads until it fails, or the term ends with no leader and a new one begins.
Node 4 leads term 1, elected at 250 ms.
- Node 1Follower
- Term
- 1
- Voted for
- Node 4
- Leader
- unknown
- Timer
- Times out in 258 ms
- Node 2Candidate
- Term
- 1
- Voted for
- Node 2
- Votes
- 1 of 5
- Timer
- Times out in 225 ms
- Node 3Follower
- Term
- 1
- Voted for
- Node 4
- Leader
- unknown
- Timer
- Times out in 140 ms
- Node 4Leader
- Term
- 1
- Voted for
- Node 4
- Leader
- Node 4
- Timer
- Heartbeat every 50 ms
- Node 5Follower
- Term
- 1
- Voted for
- Node 4
- Leader
- unknown
- Timer
- Times out in 193 ms
Cluster settings
Each node waits a random time in this range before it runs for leader. A narrow range makes ties likely.
The same seed gives the same timeouts.
Event log
Newest first. Showing 12 of 12 entries.
- 250 msLeaderNode 4 becomes leader of term 1 with 3 of 5 votes
- 243 msVoteNode 1 rejects Node 2 in term 1: already voted for Node 4
- 241 msVoteNode 4 rejects Node 2 in term 1: already voted for Node 4
- 241 msVoteNode 3 rejects Node 2 in term 1: already voted for Node 4
- 239 msVoteNode 5 rejects Node 2 in term 1: already voted for Node 4
- 239 msVoteNode 5 votes for Node 4 in term 1
- 239 msVoteNode 1 votes for Node 4 in term 1
- 238 msVoteNode 2 rejects Node 4 in term 1: already voted for Node 2
- 236 msVoteNode 3 votes for Node 4 in term 1
- 232 msTimeoutNode 2 timed out, starts term 1
- 230 msTimeoutNode 4 timed out, starts term 1
- 0 msInfo5 nodes start as followers in term 0
What it shows
Raft timeouts are random. If they were all equal, every node would run for leader at once and split the vote. A spread of timeouts means one node usually fires first and wins before the others wake up.
Narrow the range of timeouts until elections start failing. Crash nodes, cut off the leader or split the network and watch a new leader emerge. It covers leader election only (sections 5.1 and 5.2 of the Raft paper), not log replication.
How to read it
- The page opens with a leader already elected. “Start over” returns to time zero.
- Play runs at a quarter of real time. “Next event” jumps to the next change. “Run to next leader” skips ahead until someone wins.
- Each node card shows its term, its vote and when its timer fires. Term and vote survive a crash, as the paper requires. Role does not.
- “Crash” and “Restart” stop and start a node. “Move to side A or B” splits the network: nodes only hear their own side.
- The tool warns if broadcast time, election timeout and time between failures break the paper’s rule of thumb.
- The event log lists every timeout, vote, step-down and fault, newest first.
Questions
Why must a candidate win a majority of votes?
Any two majorities of the same cluster share at least one node, and a node votes only once per term. So two candidates can never both win the same term. This is the election safety property in section 5.2 of the paper.
Can a minority partition elect a leader?
No. A candidate that can reach fewer than a majority of all nodes can never collect enough votes, however long it waits. Its term just keeps rising as it times out and tries again. Crash three of five nodes to see it.
Why does the old leader keep leading after a partition?
A leader only steps down when it sees a higher term. Cut off in a minority, it hears nothing, so it still believes it leads. Real systems add measures such as check-quorum, and a leader without a majority can’t commit anything, which keeps the data safe. This simulator leaves them out, so you see the bare protocol.
What is a split vote?
Two or more nodes become candidates in the same term, and the votes divide so that nobody reaches a majority. The term ends with no leader, and the candidates’ timers fire again at new random times. Randomised timeouts make a repeat unlikely, and a narrow range makes it likely.
How much of Raft does this cover?
Leader election only. The paper also covers log replication, safety rules that restrict who can win based on the log, and membership changes. None of those are modelled, so every candidate here is treated as equally up to date.
Learn it properly
Sources
Explore further
- The Secret Lives of Data: RaftAn animated, step-by-step walk through leader election and log replication.
Last updated
More tools
All tools- estimatorBack-of-envelope estimatorTurn daily users into requests per second, storage and bandwidth, with the working shown.Open tool
- simulatorConsistent hashing simulatorA hash ring with virtual nodes: key spread per node, and how many keys move when the cluster changes.Open tool
- estimatorQueue latency estimatorWhy latency explodes as servers get busy: utilisation, waiting time and Little’s law.Open tool