ZooKeeper yes Apache A software project of the software foundation , It provides open source distributed configuration services for large-scale distributed computing 、 Synchronization service and naming registration .

ZooKeeper The architecture achieves high availability through redundant services .

Zookeeper The design goal of is to encapsulate those complex and error prone distributed consistency Services , Form an efficient and reliable primitive set , And provide users with a series of simple and easy-to-use interfaces .

A typical distributed data consistency solution , Distributed applications can implement such as data publishing based on it / subscribe 、 Load balancing 、 Naming service 、 Distributed coordination / notice 、 Cluster management 、Master election 、 Distributed locks and distributed queues .

Who is suitable for reading this tutorial ?

This tutorial is for professional program developers , Through this tutorial, you can learn... Step by step zookeeper Application of .

zookeeper Data structure

zookkeeper The namespace provided is very similar to the standard file system ,key-value Store in the form of . name key By slash / Split a series of path elements ,zookeeper Each node in the namespace is identified by a path .

relevant CAP theory

CAP The theory points out that for a distributed computing system , It is impossible to satisfy the following three points at the same time :

  • uniformity : In a distributed environment , Consistency refers to whether data can be consistent between multiple copies , It is equivalent to all nodes accessing the same latest copy of data . Under the requirement of consistency , When a system performs an update operation in the state of consistent data , It should be ensured that the data of the system is still in a consistent state .
  • usability : Get the correct response for each request , However, it is not guaranteed that the data obtained is the latest data .

  • Partition fault tolerance : When the distributed system encounters any network partition failure , There is still a need to ensure external services that meet consistency and availability , Unless the entire network environment fails .

A distributed system can only satisfy consistency at most (Consistency)、 usability (Availability) And partition fault tolerance (Partition tolerance) Two of these three .

Of these three basic needs , At most two of them can be met at the same time ,P It is necessary , So only in CP and AP Select ,zookeeper The guarantee is CP, contrast spring cloud Registry in the system eruka The realization is AP.

BASE theory

BASE yes Basically Available( Basically available )、Soft-state( Soft state ) and Eventually Consistent( Final consistency ) Abbreviations for three phrases .

  • Basically available : Failure in distributed system , Allow partial loss of availability ( Service degradation 、 Page degradation ).

  • Soft state : Allow distributed systems to have intermediate states . Moreover, the intermediate state does not affect the availability of the system . The intermediate state here refers to different data replication( Data backup node ) The final consistency of delay can occur between data updates .

  • Final consistency :data replications Consistency over time .

BASE The theory is right CAP The result of a trade-off between consistency and availability , The core idea of the theory is : We can't achieve strong consistency , But each application can be based on its own business characteristics , Adopt appropriate methods to achieve the final consistency of the system .

Related resources

zookeeper Official website :https://zookeeper.apache.org/