Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 17/ 31
Distributed Systems & Architecture

Distributed Consensus & Coordination

Keep a cluster agreed on one leader and replicated state log even when nodes crash.

AdvancedRaft · Quorum · Leader Election3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
Raft, Quorums & Preventing Split-Brain

Understand terms, randomized election timers, and why minority partitions cannot elect a second leader.

Advanced
ZooKeeper, etcd & Paxos vs. Raft

Where coordination services fit in real architectures (and what NOT to put in them).

Advanced

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

Loading interactive diagram
Loading interactive exercise

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.

Key takeaway: Always deploy consensus clusters with an odd number of nodes (3 or 5) across separate failure zones.

How it works, step by step

Step 1 of 4
Leader Election

1. 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.

At most one leader can win a majority in any term
Key numbers at this step
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

3-Node Consensus Cluster
Best for: Standard coordination metadata (tolerates 1 node failure)

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.

5-Node Consensus Cluster
Best for: Production control planes (Kubernetes etcd, shard routers)

Strengths: Tolerates 2 simultaneous failures (1 planned upgrade + 1 unexpected crash).

Watch out: Slightly higher replication fan-out; odd numbers prevent tied votes.

Gossip Protocols (SWIM / Cassandra)
Best for: Large clusters (100–10,000 nodes) tracking membership/liveness

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?
Interview tip: Explicitly separate the Control Plane (Raft/etcd for small metadata) from the Data Plane (sharded storage/caches).

Knowledge check

Loading quiz

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.

Open AI HLD Practice →SD Interview Q&A
Previous topic
Consistency Models
Next topic
Distributed Locks & Unique IDs