← Lessons

quiz vs the machine

Gold1400

Databases

Consensus With Raft Revisited

Raft turns the hard problem of agreement into an elected leader appending entries that a majority must accept before they count.

5 min read · core · beat Gold to climb

Agreement Through a Leader

Consensus means a group of nodes agree on a single sequence of values even when some fail. Raft makes this approachable by electing one leader that owns all client writes, so followers never have to reconcile competing proposals.

Terms and Elections

Time is divided into numbered terms. Each term has at most one leader. A node that hears nothing from a leader becomes a candidate, increments the term, and requests votes. A candidate that wins a majority becomes leader. Because each node votes once per term, two leaders cannot both win the same term.

Replicating the Log

The leader appends client commands to its log and sends them to followers.

  • An entry is committed once it lives on a majority of nodes.
  • Committed entries are then applied to the state machine in log order.
  • A new leader must already hold all committed entries, which the voting rules guarantee.

Why a Majority

A majority of any two majorities always overlap on at least one node, so a committed entry survives any election. That overlap is what keeps the log consistent across leader changes.

Key idea

Raft elects one leader per term and commits a log entry only after a majority stores it, so overlapping majorities preserve agreement across failures.

Check yourself

Answer to earn rating on the learn ladder.

1. When is a Raft log entry considered committed?

2. Why can two leaders not be elected in the same term?

3. Why does requiring a majority preserve committed entries across leader changes?