ZooKeeper Basic Principle

ZooKeeper Overview

ZooKeeper is a distributed, highly available coordination service. ZooKeeper provides two functions:

ZooKeeper Architecture

Nodes in a ZooKeeper cluster have three roles: Leader, Follower, and Observer. Figure 1 shows the ZooKeeper architecture. Generally, an odd number (2N+1) of ZooKeeper servers are configured. At least (N+1) vote majority is required to successfully perform write operation.

Figure 1 ZooKeeper architecture

Table 1 describes the functions of each module shown in Figure 1.

Table 1 ZooKeeper modules

Module

Description

Leader

Only one node serves as the Leader in a ZooKeeper cluster. The Leader, elected by Followers using the ZooKeeper Atomic Broadcast (ZAB) protocol, receives and coordinates all write requests and synchronizes written information to Followers and Observers.

Follower

Follower has two functions:

  • Prevents SPOF. A new Leader is elected from Followers when the Leader is faulty.
  • Processes read requests and interacts with the Leader to process write requests.

Observer

The Observer does not take part in voting for election and write requests. It only processes read requests and forwards write requests to the Leader, increasing system processing efficiency.

Client

Reads and writes data from or to the ZooKeeper cluster. For example, HBase can serve as a ZooKeeper client and use the arbitration function of the ZooKeeper cluster to control the active/standby status of the HMaster.

If security services are enabled in the cluster, authentication is required during the connection to ZooKeeper. The authentication modes are as follows:

ZooKeeper Principle