Zookeeper's ZAB Protocol
Let’s explore the phases of the ZAB protocol.
We'll cover the following
As mentioned previously, the Zookeeper atomic broadcast protocol (ZAB) is used to agree on a leader in the ensemble, synchronize the replicas, manage the broadcast of update transactions, and recover from a crashed state to a valid state.
This protocol shares a lot of characteristics with other consensus protocols, such as Paxos or Raft.
In ZAB, transactions are identified by a specific type of identifier, called zxid. This identifier consists of two parts , where is the epoch number of the leader that generates the transaction and is an integer acting as a counter for this epoch.
The counter is incremented every time a new transaction is introduced by the leader, while is incremented when a new leader becomes active.
ZAB protocol Phases
The protocol consists of four basic phases as shown in the following illustration:
Leader election
In the first phase, the state election initializes the peers. This phase gets terminated as soon as a quorum of peers votes for a leader. This leader is prospective and will become an established leader only at the end of phase three.
Discovery
In the second phase, the leader communicates with the followers to discover the most up-to-date sequence of accepted transactions among a quorum and establish a new epoch so previous leaders cannot commit new proposals.
Synchronization
In the third phase, the leader synchronizes the replicas in the ensemble using the leader’s updated history from the previous phase. The leader is established at the end of this phase.
Broadcast
In the last phase, the leader receives write requests and performs broadcasts of the associated transactions. This phase lasts until the leader loses its leadership, which is essentially maintained via heartbeats to the followers.
Note: Practically, Zookeeper uses a leader election algorithm called Fast Leader Election (FLE), to employ an optimisation. It attempts to elect a leader that has the most up-to-date history from a quorum of processes. This algorithm minimizes the data exchange between the leader and the followers in the Discovery phase.
Get hands-on with 1400+ tech skills courses.