Consensus: Raft
Lesson, slides, and applied problem sets.
View SlidesLesson
Consensus: Raft
Why consensus
Replication without agreement leads to divergence. Consensus ensures a single, consistent log despite failures.
Raft at a glance
Raft splits the problem into three parts:
- Leader election
- Log replication
- Safety
Elections
A follower grants a vote if:
- Candidate term is up-to-date
- Candidate's log is at least as up-to-date
- Follower hasn't voted for someone else in this term
What you will build
- Vote granting logic
- AppendEntries conflict handling
- Full AppendEntries (term-by-term)
- Commit index calculation
- Conflict backtracking optimization
- Snapshot log compaction
- Joint consensus commit index
- Election timeout scheduling
Module Items
Raft Vote Grant
Decide whether a follower should grant a vote to a candidate.
Raft AppendEntries
Apply Raft append-entries rules to a follower log.
Raft AppendEntries (Full)
Apply full Raft AppendEntries conflict rules.
Raft Commit Index
Compute the largest committed index for the current term.
Raft Conflict Backtracking
Compute leader nextIndex from a conflict reply.
Raft Snapshot Compaction
Compact a log after installing a snapshot.
Raft Election Timeouts
Schedule election timeouts from heartbeat gaps.
Raft Joint Consensus Commit
Compute commit index under joint consensus.
Raft Milestone: Follower RPC Handling
Handle RequestVote and AppendEntries RPCs for a Raft follower.