The ZAB Protocol: How ZooKeeper Achieves Consensus Without Being Paxos or Raft

2026-09-02

ZooKeeper Atomic Broadcast (ZAB) is the consensus protocol that powers Apache ZooKeeper — the coordination service behind Kafka, HBase, Solr, and countless other distributed systems. It predates Raft and diverges from Paxos in one crucial way: ZAB is designed for primary-backup replication with strict ordering guarantees, not for agreeing on a single value at a time.

The core insight: ZooKeeper's clients issue a stream of state-mutating operations, and every replica must apply them in the exact same order. Paxos gives you agreement on individual values but doesn't natively guarantee total order across a sequence. ZAB bakes total order in from the start.

How it works. ZAB has two modes:

The zxid trick. Because the high 32 bits encode the epoch, transactions from a new leader are always ordered after those from the old leader, even if the counter resets. A follower comparing (epoch=5, counter=100) vs (epoch=6, counter=1) immediately knows the second is newer. This makes recovery reasoning tractable.

Real-world example: Kafka historically used ZooKeeper to store broker metadata, topic configurations, and consumer offsets. When a broker updated a topic's partition assignment, that write went through ZAB: leader proposed it, quorum acked, all ZooKeeper nodes applied it in the same order. This is why two Kafka brokers reading ZooKeeper at the same time never see contradictory topic state — ZAB's total ordering guarantees it. (Kafka has since moved to KRaft, its own Raft implementation, but the pattern persisted for a decade.)

Rule of thumb: ZAB needs a quorum of ⌊N/2⌋ + 1 nodes to make progress, same as Paxos/Raft. For a 5-node ensemble, you can lose 2 and still commit. But every write requires 2 round trips (PROPOSE + COMMIT) — so expect ~2× the base network latency per write.

When ZAB vs Raft? If you're building from scratch today, use Raft — it's better documented and has more library support. Choose ZooKeeper (and thus ZAB) when you need a proven coordination service with mature client libraries, watches, and ephemeral nodes.

Key Takeaway: ZAB achieves consensus by giving every transaction a leader-epoch-tagged zxid and requiring new leaders to inherit the highest committed zxid — trading Paxos's flexibility for guaranteed total order.

All newsletters