The leader and the log
Raft is a consensus protocol designed for understandability. At any time one node is the leader, elected for a numbered term. Clients send commands to the leader, which appends each as an entry to its log and replicates it to followers with append entries messages.
Each entry records its term and an index, and the leader includes the previous entry's term and index so followers can verify their logs match.
Committing an entry
An entry becomes committed once the leader has stored it on a majority of nodes. The leader tracks a commit index marking the highest committed entry, and it tells followers to apply entries up to that point to their state machines.
- A follower rejects an append if the previous entry does not match, forcing the leader to back up and resend until logs align.
- This log matching property guarantees that if two logs agree at an index, they agree on all earlier entries.
Safety on leader change
A new leader must contain all committed entries, enforced by only granting votes to candidates whose log is at least as up to date. This prevents a stale node from erasing committed data.
Key idea
Raft replicates a log through an elected leader, committing an entry once a majority stores it and using log matching to keep followers consistent.