LabHub

Blog

Distributed Consensus Deep Dive — Paxos, Raft, ZAB, FLP, etcd, ZooKeeper, KRaft, BFT, CRDT (2025)

한국어English

"The problem with distributed systems is that the parts of the system you don't think about are the parts that will fail." — Leslie Lamport

Why does Kubernetes depend on etcd? Why did Kafka replace ZooKeeper with KRaft? Why does the PostgreSQL HA solution Patroni require a "DCS" (Distributed Configuration Store)? The answer is the same in every case: distributed consensus.

Getting several nodes to "agree" on a single decision is trivial locally, but as soon as a network enters the picture it becomes a domain of mathematically proven impossibility. This post is a map that starts from the shock of the FLP result, walks through the elegance of Paxos and Raft, and reaches the 2025 consensus landscape (KRaft, BFT, CRDTs) in one sweep.


1. Problem Definition — Why "Agreement" Is Hard

What Consensus Must Guarantee

  1. Agreement — every correct node reaches the same value
  2. Validity — the decided value must be one that some node proposed
  3. Termination — eventually a decision is made

The Hostile Reality of Distributed Environments

The FLP Impossibility Result (1985)

The shocking proof by Fischer, Lynch, and Patterson:

In an asynchronous distributed system, if even a single node can fail-stop, no deterministic consensus algorithm exists.

That is, an algorithm that perfectly satisfies "Agreement + Validity + Termination" cannot exist mathematically.

So What Do We Do?

Both Paxos and Raft go in this direction.


2. Paxos — Lamport's Monument

Arrival

Proposed by Leslie Lamport in his 1990 paper "The Part-Time Parliament." It was a satire modeled on the parliament of the ancient Greek island of Paxos. The reviewers didn't get the joke, so it was rejected, and only published in 1998.

In 2001 he re-explained it in "Paxos Made Simple," but... it is still hard. Even Lamport himself:

"I have never actually implemented Multi-Paxos."

Basic Paxos Roles

The 2-Phase Protocol

Phase 1 (Prepare)

  1. A proposer picks a number n and broadcasts Prepare(n)
  2. An acceptor "if it has never seen a number larger than n" promises, and returns any previously accepted value

Phase 2 (Accept)

  1. Once a majority responds, the proposer broadcasts Accept(n, v) — with the previously accepted value if one exists, otherwise its own
  2. An acceptor accepts "if it hasn't promised against a higher n"
  3. On majority acceptance, the value is decided

Why It's Hard

Real-World Uses


3. Raft — "Understandable Consensus"

Motivation

In 2014, Diego Ongaro and John Ousterhout (Stanford) published "In Search of an Understandable Consensus Algorithm." The goal was exactly one thing: more understandable than Paxos.

Key Decomposition

Raft breaks consensus into three parts:

  1. Leader Election — pick a leader
  2. Log Replication — the leader replicates the log
  3. Safety — consistency even when a leader dies

States

Each node is in one of three states:

Leader Election

  1. If a follower fails to receive a heartbeat from the leader for electionTimeout (randomized 150-300ms), it transitions to Candidate
  2. It increments the term, votes for itself, and broadcasts RequestVote
  3. Majority of votes → Leader. On a tie, retry after timeout.
  4. Thanks to the randomized timeout, split votes naturally resolve

Log Replication

  1. Client → request to leader
  2. Leader appends to its own log and broadcasts AppendEntries to followers
  3. Once a majority of followers confirm, it is "committed"
  4. The leader applies to the state machine and replies to the client
  5. Followers also receive the commit index and apply

Safety — Log Matching Property

Real-World Raft Implementations

Joint Consensus — The Elegance of Membership Changes

When adding/removing nodes, you pass through a Joint Consensus stage in which the two configurations coexist, enabling zero-downtime changes. Mistakes here are a shortcut to split-brain, so the paper emphasizes this heavily.


4. ZooKeeper and ZAB

ZooKeeper's History

ZAB (ZooKeeper Atomic Broadcast)

Similar to Paxos, but:

The Znode Model

ZooKeeper Use Cases

Limitations


5. KRaft — Why Kafka Dropped ZooKeeper

Motivation

KRaft Arrives

Internals

Benefits

Migration

ZooKeeper → KRaft migration happened en masse at large enterprises in 2024-2025. "Every Kafka cluster eventually converges to KRaft."


6. etcd — The Heart of Kubernetes

Why Kubernetes Uses etcd

All state of the K8s API Server (Pods, Services, ConfigMaps, Secrets) is stored in etcd. Leader election and distributed locks are etcd-based as well.

Raft Implementation

Performance Characteristics

Operational Tips

etcd vs ZooKeeper vs Consul

AspectetcdZooKeeperConsul
LanguageGoJavaGo
ConsensusRaftZABRaft
Data modelflat KVhierarchical treeKV + service discovery
Watchstreamone-shotstream
Health checksexternalephemeralbuilt-in
Main usageKubernetesKafka (legacy), HadoopService mesh, legacy HA

The 2025 mainstream: new projects use etcd or Consul, Kafka moves to KRaft.


7. Byzantine Fault Tolerance (BFT)

The Byzantine Generals Problem

Lamport's classic problem (1982): generals besieging an enemy position try to agree on attack/retreat via messengers, but traitor generals may send false messages. How can the majority reach a correct decision?

Are Paxos/Raft BFT?

No. They only assume Crash Fault Tolerance (CFT):

If malicious nodes (hacking, bugs) exist, Paxos/Raft break.

PBFT (Practical Byzantine Fault Tolerance)

HotStuff (2018)

Blockchain and BFT

Do Enterprises Need BFT?


8. CRDT — Convergence Magic Without Consensus

Motivation

Consensus is expensive. It needs network round-trips + majority agreement. Offline, it doesn't even work. And yet...

Collaborative documents (Google Docs), messaging (WhatsApp), shopping carts all "eventually converge to the same state" without consensus. How?

CRDT (Conflict-free Replicated Data Type)

Two Flavors

State-based (CvRDT): share full state; merge(a, b) is a semilattice (join) operation

Operation-based (CmRDT): share operations, messages delivered over ordered/reliable channels

Famous CRDT Implementations

Post-2024 — Local-First


9. Weak Consistency Models

The Consistency Spectrum

Strong ← Linearizable → Sequential → Causal → Eventual → Weak

Linearizable (Strong Consistency)

Causal Consistency

Eventual Consistency

Misunderstandings of the CAP Theorem


10. Distributed Locks — An Application of Consensus

The ZooKeeper Approach

  1. Create a sequential + ephemeral znode under /locks/resource/
  2. Watch the znode with the next-smaller number than yours
  3. When that one is deleted, it's your turn

The etcd Approach

lease = client.grant(10)  # 10-second TTL
client.put("/lock", "me", lease)  # acquire the lock on success

Redlock (Redis) — Controversial

As covered in the earlier Redis post:

Fencing Tokens


11. Leader Election in Practice — Pitfall Guide

Split Vote

In Raft, if multiple Candidates start voting at the same term simultaneously → no one gets a majority

Leader Flapping

Frequent leader changes due to network instability:

Network Partition (Brain Split)

Clock Drift


12. The 2025 Consensus Landscape

Mainstream

Emerging

Frontier


13. Top 10 Distributed-Consensus Anti-patterns

  1. "Roll your own Paxos" — guaranteed failure
  2. Fork a Raft library and patch on top — you'll miss upstream fixes
  3. A 4-node cluster instead of odd — quorum of 3 tolerates two splits
  4. Consensus over the WAN — latency explosions, regional splits
  5. Leaving ZooKeeper session timeout at default — long GCs lead to cascades
  6. Ignoring etcd's 8GB limit — one day, a sudden outage
  7. Raft in an environment that needs Byzantine tolerance — one malicious node ruins everything
  8. Heavy writes to a consensus system — KV only, values over 1MB forbidden
  9. Home-grown distributed locks — 99% buggy
  10. Using Eventual Consistency as if it were Strong — data forks

14. Using Distributed Consensus Wisely — Checklist


Closing — The Paradox of Consensus

Every interesting problem in distributed systems ultimately reduces to consensus. Kubernetes agreeing on pod state, Kafka electing partition leaders, blockchains ordering transactions, collaborative docs merging edits — all of it.

As the FLP theorem says, "perfect consensus" is mathematically impossible. Every algorithm we use is a pragmatic compromise between safety and liveness. Paxos is elegant but hard, Raft is understandable but full of details, BFT is powerful but expensive, and CRDTs are an alternative that avoids consensus.

"The only way to make distributed systems simple is to understand that they're fundamentally hard, and stop pretending otherwise." — Kyle Kingsbury (Jepsen)


Next Up — Modern CI/CD Pipelines, Fully Disassembled

If consensus is the heart of distributed systems, CI/CD is the circulatory system of modern development. In the next post:

A journey to complete the last piece of the developer productivity puzzle.


"The impossibility of consensus is not a bug in distributed systems — it's the fundamental feature that makes them interesting." — Leslie Lamport (Turing Award lecture, 2013)

Comments

No comments yet.

Sign in to leave a comment