Why elect a leader
In a replicated cluster, having one leader simplifies ordering: clients write only to the leader, which replicates entries to followers. Raft makes leadership a first class concept so the cluster always agrees on who is in charge.
Terms and votes
Time is divided into terms, each a monotonically increasing number. A follower that hears nothing from a leader for its election timeout becomes a candidate, increments the term, and requests votes.
- Each server grants at most one vote per term.
- A candidate wins when it collects votes from a majority.
- Majority guarantees at most one leader per term.
Avoiding split votes
If two candidates start at once, votes may split and no one wins. Raft uses randomized election timeouts so one server usually times out first, becoming the sole candidate and winning cleanly.
Key idea
Raft elects exactly one leader per term by requiring a majority vote, and breaks ties with randomized timeouts so the cluster converges quickly.