Generally speaking, zooKeeper is used in the following scenarios:
- Distributed coordination
- A distributed lock
- Metadata/configuration information management
- HA High availability
Distributed coordination
This is actually A classic use of ZooKeeper. In simple terms, it is like that you send A request to MQ, and then system B consumes the message and processes it. How does system A know the result of system B? Zookeeper can be used to coordinate distributed systems. After system A sends the request, it can register A listener for the value of A node on ZooKeeper. Once system B finishes processing, it can modify the value of the ZooKeeper node, and system A can receive notification immediately and solve the problem perfectly.
A distributed lock
Here’s an example. When two consecutive modification operations are performed on a single piece of data, both machines receive the request at the same time, but only one machine can execute the other machine first. Zookeeper distributed lock can be used at this time. After a machine receives a request, it first obtains a distributed lock on ZooKeeper, that is, it can create a ZNode and then perform operations. Then another machine tried to create the ZNode, only to find that it couldn’t because someone else had created it and had to wait until the first machine had finished executing it.
Metadata/configuration information management
Zookeeper can be used to manage the configuration information of many systems, such as Kafka, Storm and many other distributed systems use ZooKeeper to manage metadata and configuration information, including dubbo registry.
HA High availability
For example, many big data systems such as Hadoop, HDFS, and YARN choose to develop HA mechanisms based on ZooKeeper. That is, an important process usually has two main and standby processes. When the main process dies, zooKeeper detects that the main process is switched to the standby process immediately.