Why it matters

Consensus is the foundation of every strongly-consistent distributed system. Raft's clear structure (leader election + log replication + safety) makes it teachable and implementable. This is why it displaced Paxos as the practical default.

Advertisement

The architecture

Roles: Leader (accepts client writes, replicates), Followers (accept writes from leader, respond to heartbeats), Candidates (during election).

Terms: monotonically increasing numbers identifying leader epochs. Every message includes the sender's term.

Raft rolesLeaderone per termFollowersN-1 nodesCandidatesduring electionTerms increment on each election; higher term always wins
Raft node roles.
Advertisement

How it works end to end

Leader election: on heartbeat timeout, follower becomes candidate, increments term, votes for itself, requests votes from others. Majority (N/2 + 1) grants leadership.

Log replication: leader accepts client commands, appends to log, sends AppendEntries to followers. Followers append and ack. Once majority acks, leader commits and applies.

Safety: Raft guarantees committed entries are never overwritten. Leader completeness invariant: any leader for a term contains all committed entries from previous terms.