Skip to main content
← CONCEPTS / DISTRIBUTED SYSTEMS
An end-to-end domain learning journey

Consistency & Consensus Replication
(Raft / Paxos).

Fault-tolerant replication protocols (Raft, Multi-Paxos, Quorum) that keep distributed state consistent across node crashes and network partitions using majority quorums (2f+1) and monotonic term numbers.
Start the journey7 sections· Last modified Nov 29, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

If replicas diverge under asymmetric network delays, use Raft/Paxos quorums when you need linearizable state (locks, metadata, ledgers), and remember that even-numbered clusters add cost without improving fault tolerance.

TL;DR30-second simplified summary
▾

Core Mechanics: Consensus protocols (Paxos, Raft, ZAB) let a cluster of unreliable machines agree on an ordered sequence of state transitions—and never lose a committed write—even when nodes crash or networks partition.

Visual & Structural Flow: Depicts 3-Node Raft Cluster: Leader AppendEntries + Quorum Commit (term=4) (Node A (Leader, t=4) -> Node B (Follower) -> Node C (Follower)); How Raft Leader Lease / ReadIndex Prevents Stale Ex-Leader Reads (Client -> Leader (t=4) -> Follower B -> Follower C); Follower -> Candidate -> Leader State Machine (FOLLOWER -> CANDIDATE -> LEADER).

Trade-Offs & Production: Compare fault tolerance, write latency, and consistency guarantees. Production CockroachDB / etcd clusters deploy 3 or 5 nodes across 3 Availability Zones on dedicated NVMe WAL disks, serving linearizable reads via ReadIndex/leader.

Failure Modes & Application: Explore Raft safety invariants, split-brain recovery, and distributed key-value stores.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
PRIME Core Invariants & Workload Constraints
Establish concrete scale, latency, memory, and concurrency bounds for Consistency & Consensus Replication (Raft / Paxos) before selecting data structures or storage components.
Failure Boundaries & Operational Trade-Offs
Identify hot-key skew, partial failures, resource leaks, and when simpler single-node or standard alternatives outperform complex designs.
Full walkthrough · 7 stages
01
STAGE 01 · WHAT IT ISL4 · FUNDAMENTALS

What is Consensus Replication (Raft & Multi-Paxos).

Why this matters: The mechanism: understand how Consensus Replication (Raft & Multi-Paxos) works from first principles.

Consensus protocols (Paxos, Raft, ZAB) let a cluster of unreliable machines agree on an ordered sequence of state transitions—and never lose a committed write—even when nodes crash or networks partition.

They combine monotonic term/ballot numbers (fencing stale leaders) with intersecting majority quorums (⌊N/2⌋+1\lfloor N/2 \rfloor + 1): 3 nodes tolerate 1 failure; 5 nodes tolerate 2. Raft decomposes consensus into Leader Election (RequestVote with log-freshness check), Log Replication (AppendEntries with prevLogIndex/prevLogTerm), and Safety.

Raft Majority Quorum

3-Node Raft Cluster: Leader AppendEntries + Quorum Commit (term=4)

Node A (Leader, t=4)WAL fsync idx=108Node B (Follower)fsync + ACK (2/3 quorum)Node C (Follower)Catching up…AppendEntries(prev=107,t=4)

1.Odd Cluster Sizing: A 4-node cluster has quorum 3 (tolerates 1 failure)—identical fault tolerance to 3 nodes at higher cost.

2.Log-Freshness Election: A candidate can only win RequestVote if its log is at least as up-to-date as a majority.

3.1-RTT Commit: Once 2 of 3 nodes fsync index 108, the leader commits and applies it to the state machine.

Intersecting majorities guarantee any newly elected leader already holds every committed log entry.

02
STAGE 02 · WHY WE NEED ITL4 · FUNDAMENTALS

Why we need Consensus (and how stale leaders & shared disks break it).

Why this matters: The problem: see what breaks without Consensus under real concurrency or scale.

Naive primary-replica async replication loses committed writes on failover (RPO > 0) and risks split-brain if the old primary stays reachable.

Even in Raft/Paxos clusters, three operational hazards cause outages:

  1. Stale Leader Reads: Serving reads from a leader without ReadIndex or valid hardware leases lets an isolated ex-leader return stale data.
  2. WAL Disk Starvation: Sharing Raft WAL disks with app logs or container pulls spikes fsync past electionTimeout, triggering cascading elections.
  3. Membership Change Split-Brain: Adding 2 nodes at once without single-node steps or Joint Consensus can create two disjoint majorities.
Linearizable ReadIndex

How Raft Leader Lease / ReadIndex Prevents Stale Ex-Leader Reads

ClientLeader (t=4)Follower BFollower C1. Linearizable GET balance2. Heartbeat confirm still leader3. ACK (quorum confirms t=4)4. Apply up to commitIndex -> $450

ReadIndex confirms leadership with a heartbeat quorum before serving local state, avoiding a disk log write on reads.

Engineering Decision Framework
Problem
How to implement Consistency & Consensus Replication (Raft / Paxos) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
If replicas diverge under asymmetric network delays, use Raft/Paxos quorums when you need linearizable state (locks, metadata, ledgers), and remember that even-numbered clusters add cost without improving fault tolerance.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Consistency & Consensus Replication (Raft / Paxos) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

Multi-Raft Sharding

CockroachDB and TiKV split data into 64-96 MB key ranges, running thousands of independent Raft groups per node with coalesced heartbeats.

Dedicated NVMe for Raft WAL

Isolate etcd/Raft WAL onto dedicated low-latency NVMe so fsync never stalls past electionTimeout.

03
STAGE 03 · WHERE IT IS USEDL5 · APPLIED DESIGN

Where Consensus Replication is used.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Think of Where Consensus Replication is used as the intuition layer for Consistency & Consensus Replication (Raft / Paxos): Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Use Raft/Paxos wherever zero data loss (RPO=0) and linearizable metadata/state are non-negotiable.

ChoiceWhat it buysWhat it costs
Cluster Metadata & Coordination (etcd, ZooKeeper, Consul)Linearizable leader election, service discovery, and monotonic fencing tokens.Not designed for multi-terabyte bulk storage or high-QPS analytics.
Distributed NewSQL / KV (CockroachDB, TiKV, Spanner)Multi-Raft scales horizontally across 64-96 MB ranges with ACID transactions.1-RTT quorum replication tax on every write; cross-region latency if replicas span continents.
Avoid: High-Volume Telemetry / Ephemeral SessionsUse Kafka/ClickHouse or Redis without Raft fsync overhead.Paying quorum fsync on every clickstream event wastes IOPS and latency.
04
STAGE 04 · HOW IT IS MANAGEDL5 · APPLIED DESIGN

How Raft AppendEntries, WAL fsync, and Snapshots are managed.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Think of How Raft AppendEntries, WAL fsync, and Snapshots are managed as the intuition layer for Consistency & Consensus Replication (Raft / Paxos): Operational control: configure bounds, failure handling, and safe production defaults.

Always fsync Raft terms, votes, and log entries before acknowledging RPCs; compact logs with snapshots (InstallSnapshot) while throttling snapshot bandwidth so followers don't starve.

Request & State Flow

How Raft AppendEntries, WAL fsync, and Snapshots are managed

Workload &ConstraintsBounds & SLOsHow RaftAppendEntries, WAL…Invariant pathVerified StateBounded outcomeBounds & SLOsInvariant path
# Core Raft AppendEntries log-consistency & commit invariant (Python)
class RaftNode:
 def __init__(self):
 self.current_term = 0
 self.log: list[tuple[int, bytes]] = [] # (term, command)
 self.commit_index = -1

 def handle_append_entries(self, term: int, prev_idx: int, prev_term: int,
 entries: list[tuple[int, bytes]], leader_commit: int) -> tuple[int, bool]:
 if term < self.current_term:
 return self.current_term, False # fence stale leader
 self.current_term = term
 if prev_idx >= 0:
 if prev_idx >= len(self.log) or self.log[prev_idx][0] != prev_term:
 return self.current_term, False # log divergence -> leader decrements nextIndex
 # Truncate conflicting suffix & append new entries (fsync before returning True!)
 self.log = self.log[:prev_idx + 1] + entries
 if leader_commit > self.commit_index:
 self.commit_index = min(leader_commit, len(self.log) - 1)
 return self.current_term, True
05
STAGE 05 · ALTERNATIVESL6 · SCALE & TRADE-OFFS

Alternatives: Raft/Paxos vs. Async Primary-Replica vs. Dynamo Quorum.

Why this matters: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Think of Alternatives: Raft/Paxos vs. Async Primary-Replica vs. Dynamo Quorum as the intuition layer for Consistency & Consensus Replication (Raft / Paxos): The trade-off: compare competing approaches across latency, consistency, and operational cost.

Compare fault tolerance, write latency, and consistency guarantees.

Design Trade-Off

Alternatives: Raft/Paxos vs. Async Primary-Replica vs. Dynamo Quorum

Before · Seq Scan + Unbounded Bloat
  • Implicit cast breaks B-Tree
  • Deadlock or XID wraparound risk
  • Long tx blocks VACUUM
After · Indexed Plan + Bounded MVCC
  • Index-only scan in <2 ms
  • Deterministic lock ordering
  • Autovacuum keeps bloat flat
ChoiceWhat it buysWhat it costs
Raft / Multi-Paxos (etcd, CockroachDB)2f+1 majority quorum; zero committed data loss (RPO=0); linearizable.1 quorum RTT + fsync per write; minority partition cannot accept writes.
Async Primary-Replica (Standard Postgres/MySQL)1 local fsync write latency; simple single-primary reads/writes.Unreplicated tail lost on primary crash (RPO > 0); manual/orchestrator failover.
Leaderless Dynamo Quorum (Cassandra)Tolerates partitions with sloppy quorums; high write availability.Eventual consistency; concurrent writes require LWW or CRDT reconciliation.
06
STAGE 06 · PRODUCTION ARCHITECTUREL7 · STAFF / PRINCIPAL

Production example: 5-Node Cross-AZ Multi-Raft + ReadIndex.

Why this matters: Production architecture: see how the components compose end to end under real load.

Think of Production example: 5-Node Cross-AZ Multi-Raft + ReadIndex as the intuition layer for Consistency & Consensus Replication (Raft / Paxos): Production architecture: see how the components compose end to end under real load.

Production CockroachDB / etcd clusters deploy 3 or 5 nodes across 3 Availability Zones on dedicated NVMe WAL disks, serving linearizable reads via ReadIndex/leader leases and automating single-step membership replacements.

Raft Role Transitions

Follower -> Candidate -> Leader State Machine

electionTimeout elapsedMajority votes wonSee higher term -> step downFOLLOWERAccepts AppendEntriesCANDIDATEterm+1; RequestVoteLEADERReplicates + ReadIndex

Randomized election timeouts prevent split votes; seeing any higher term immediately fences a stale leader.

07
STAGE 07 · PROBLEMS SOLVED & FURTHER DEEP DIVEL7 · STAFF / PRINCIPAL

Problems solved by Consensus Replication & Deep Dives.

Why this matters: Applied problems: connect these internals to concrete system design and debugging scenarios.

Think of Problems solved by Consensus Replication & Deep Dives as the intuition layer for Consistency & Consensus Replication (Raft / Paxos): Applied problems: connect these internals to concrete system design and debugging scenarios.

Explore Raft safety invariants, split-brain recovery, and distributed key-value stores.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 4
Score: 0/4

Why does a 4-node Raft cluster provide no better fault tolerance than a 3-node Raft cluster?

Recommended Learning Flow