Raft
A consensus algorithm designed to be understandable. Elect a leader with randomised timeouts, replicate a log, and commit entries once a majority has them.
Raft (Ongaro and Ousterhout, 2014) solves the same problem as Paxos, keeping a cluster agreed on a replicated log, with one explicit goal: be understandable. It breaks consensus into three sub-problems you can hold in your head.
1. Leader election
Every node is a follower, a candidate or the leader. Time is divided into numbered terms.
- The leader sends regular heartbeats. While they keep coming, followers stay followers.
- If a follower hears nothing for its election timeout, it becomes a candidate, increments the term and asks for votes.
- A candidate with votes from a majority becomes leader for that term. Each node votes once per term, so there’s at most one leader per term.
- Timeouts are randomised (say 150–300 ms), so nodes rarely stand at the same moment, and split votes resolve quickly.
2. Log replication
Clients send commands to the leader. The leader appends each to its log and sends it to followers. Once a majority has stored an entry, it’s committed: the leader applies it to its state machine and tells followers to do the same. A minority of slow or crashed nodes doesn’t block progress.
3. Safety
- A candidate can only win if its log is at least as up to date as a majority’s, so a new leader always has every committed entry.
- If two logs contain an entry with the same index and term, they’re identical up to that point.
Together these mean committed entries are never lost or reordered, even through leader changes.
Living with FLP
Raft relies on timeouts, so it assumes partial synchrony. That’s how it sidesteps FLP Impossibility: under bad network conditions it may struggle to elect a leader (liveness suffers), but it never commits conflicting entries (safety holds).
Where it runs
etcd, the store behind Kubernetes’ control plane, uses Raft; so do Consul and several distributed SQL databases. A five-node cluster tolerates two failures; lose three and it stops accepting writes rather than risk divergence. That’s the CP choice in the CAP Theorem.
Why I like it
Raft is the best example I know of designing for comprehension as a feature. The paper argues that an algorithm people can understand will be implemented correctly more often, and that idea applies well beyond consensus: to APIs, codebases and documentation. The full problem statement is in The Consensus Problem.
- #distributed-systems
- #consensus
- #raft
- #replication
- #etcd
↩ Linked from (5)
- CAP TheoremEvergreen
…t confirm the latest state. You'll get an error, never a stale answer. Typical of systems built on consensus (Raft, ZooKeeper, etcd) and of anything holding money or inventory. AP: keep answering on both sides and reconc…
- FLP ImpossibilityGrowing
Use timeouts. Raft and Paxos use timeouts to suspect failures and trigger elections. Wrong suspicions cost time, never correctness. Add randomness. Randomised election timeouts, or randomised algorithms, break the advers…
- HeartbeatGrowing
Consensus: in Raft, the leader's heartbeats stop followers starting an election. Silence triggers one. Orchestrators: container platforms run liveness probes (restart if it fails) and readiness probes (stop sending traff…
- The Consensus ProblemGrowing
Paxos is correct and notoriously hard to understand and implement. That's why Raft was designed: the same guarantees, structured for humans.
- Two-Phase CommitGrowing
Fixes exist: three-phase commit (which assumes bounded delays), or making the coordinator itself fault-tolerant by replicating its log with consensus (Raft). That's roughly what modern distributed databases do.
↪ Links to (4)
Related by topic
- Evergreen
Architecture Decision Records
Career - Growingmetaphor
Balance Is a Control Loop
Calisthenics Lab - Seed
Deadlock and Starvation
Distributed systems - Evergreen
Fallacies of Distributed Computing
Distributed systems