Back to explorer
Infrastructure & Messaging 5 Min

ZooKeeper

MEDIUM

Apache ZooKeeper (Distributed Coordination)

Apache ZooKeeper is a centralized, highly reliable CP (Consistency/Partition-Tolerance) coordination service for distributed systems.


1. Core Architecture & Znodes

ZooKeeper represents cluster configurations in a tree-like hierarchy of data registers called znodes:

code
                  / (Root)
                 /    \
     /services (Persistent)  /locks (Persistent)
              /               /
    /svc-1 (Ephemeral)   /lock-0001 (Ephemeral-Sequential)

Znode Classifications

1. Persistent: Znodes that persist even after the creator client disconnects. Used for configuration states.

2. Ephemeral: Deleted automatically once the client session closes. Used for node heartbeats.

3. Sequential: ZooKeeper appends an auto-incrementing numeric suffix. Used for distributed locks and leader elections.


2. Consensus Protocol (ZAB)

ZooKeeper uses the ZooKeeper Atomic Broadcast (ZAB) protocol. ZAB runs in two primary phases:

  • Recovery (Leader Election): If the leader crashes, nodes run a vote to elect the node with the highest transactional epoch ID.
  • Broadcast: The leader proposes updates, waits for a majority write acknowledgment (quorum), and commits.

3. References & Tech Blogs