Consensus: Raft

Lesson, slides, and applied problem sets.

View Slides

Lesson

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.

    medium Sign in to access medium and hard problems
  • Raft AppendEntries

    Apply Raft append-entries rules to a follower log.

    medium Sign in to access medium and hard problems
  • Raft AppendEntries (Full)

    Apply full Raft AppendEntries conflict rules.

    hard Upgrade to Pro to access hard problems
  • Raft Commit Index

    Compute the largest committed index for the current term.

    medium Sign in to access medium and hard problems
  • Raft Conflict Backtracking

    Compute leader nextIndex from a conflict reply.

    medium Sign in to access medium and hard problems
  • Raft Snapshot Compaction

    Compact a log after installing a snapshot.

    medium Sign in to access medium and hard problems
  • Raft Election Timeouts

    Schedule election timeouts from heartbeat gaps.

    medium Sign in to access medium and hard problems
  • Raft Joint Consensus Commit

    Compute commit index under joint consensus.

    hard Upgrade to Pro to access hard problems
  • Raft Milestone: Follower RPC Handling

    Handle RequestVote and AppendEntries RPCs for a Raft follower.

    hard Upgrade to Pro to access hard problems
Join Discord