Distributed Consensus & Coordination
Keep a cluster agreed on one leader and replicated state log even when nodes crash.
In plain words
Consensus is how a group of servers agrees on one decision, such as who the leader is or what the next value is, even if some of them crash.
Think of it like…
A committee of 5 judges taking a majority vote: even if 2 are out sick, the remaining 3 can still pass valid rulings and prevent two rival rulings.
Where you’ve seen it
Kubernetes stores its cluster state in etcd, which uses Raft so its 3 or 5 nodes always agree on the state even if one goes down.
Words you’ll hear
- Leader
- The one node that coordinates decisions at a time.
- Quorum / majority
- More than half the nodes must agree (e.g. 3 of 5).
- Raft / Paxos
- Well-known algorithms for reaching consensus.
- Split brain
- Two nodes both think they are leader. Consensus prevents this.
Visual diagram
Theory & deep dive
Why 3 or 5 nodes - never 2?
Consensus algorithms like Raft and Paxos require a strict majority quorum (⌊N/2⌋ + 1) to elect a leader or commit a change. With 3 nodes, majority is 2 (tolerates 1 failure). With 5 nodes, majority is 3 (tolerates 2 failures).
With 2 nodes, majority is 2 - so losing just 1 node freezes the whole cluster (worse availability than 1 node!). That’s why etcd, ZooKeeper, and Consul always run in odd numbers: 3 or 5.
How it works, step by step
Step 1 of 41. Elect a leader via majority vote & terms
If a follower’s randomized election timeout expires without a leader heartbeat, it increments the monotonic term, votes for itself, and requests votes.
- Cluster Size
- Odd: 3 or 5 nodes
- Fault Tolerance
- (N − 1) / 2
When to use it & trade-offs
What it is
Distributed consensus algorithms (Raft, Paxos, ZAB) enable a group of nodes (3 or 5) to agree on a single leader and an ordered log of state transitions as long as a majority (quorum) stays alive.
Why it matters: Without consensus, two nodes can both think they are leader (split-brain) and corrupt data or issue duplicate locks.
When to reach for it
- Metadata stores, shard configuration directories, and service discovery (etcd, ZooKeeper)
- Replicated state machines inside modern distributed SQL (CockroachDB, TiDB, Spanner)
- Electing a single active controller/scheduler without split-brain
When to avoid or be careful
- Running an even-numbered (2 or 4 node) consensus group (adds cost without raising fault tolerance)
- Spanning a single Raft group across 3 continents for high-QPS writes (pays 150 ms per commit)
Consensus Cluster Sizing & Roles
Strengths: Low write latency (needs only 1 follower ack) and modest hardware cost.
Watch out: If 1 node is down for maintenance and a 2nd crashes, writes halt.
Strengths: Tolerates 2 simultaneous failures (1 planned upgrade + 1 unexpected crash).
Watch out: Slightly higher replication fan-out; odd numbers prevent tied votes.
Strengths: Decentralized O(log N) convergence without leader bottlenecks.
Watch out: Eventually consistent view; unsuitable for strict single-leader locking.
Interview signals & numbers to know
When this topic comes up
- split brain
- leader election
- etcd / ZooKeeper
- metadata store
- Raft / Paxos
Benchmarks & rules of thumb
- N=3 fault tolerance
- 1 node failure
- N=5 fault tolerance
- 2 node failures
- Heartbeat interval
- ~50–150 ms
- Election timeout
- ~300–1000 ms
Common mistakes & follow-ups
Common interview mistakes
- Picking 4 nodes thinking it is safer than 3 (both tolerate only 1 failure since majority of 4 is 3!)
- Storing large binary files or high-QPS analytics inside ZooKeeper/etcd
- Allowing an isolated old leader to serve reads without checking lease/quorum
Likely interviewer follow-ups
- Why do consensus clusters always use an odd number of nodes (3, 5, 7)?
- How does Raft prevent two candidates from splitting the vote forever?
- When do you use Gossip instead of Raft?
Knowledge check
Put it into practice
Design full architectures with AI feedback
Apply Distributed Consensus & Coordination inside real High-Level Design prompts or review Q&A flashcards.