Zookeeper

High Performance Distributed System Coordination Service

A high performance coordination service designed specifically for distributed systems.

Provides us with an abstraction layer for higher level distributed algorithms.

Centralized service

Distributed applications need a centralized service for the following features:

  1. configuration information
  2. naming
  3. providing distributed synchronization
  4. providing group services

Zookeeper

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.

Features

  1. open-source
  2. distributed and highly reliable
  3. centralized coordination service

It exposes a simple set of primitives that can be used by distributed applications to implement higher level services for

  1. synchronization
  2. configuration maintenance
  3. groups and naming

What makes Zookeeper a good solution?

  1. It is a distributed system itself that provides us high availability and reliability.
  2. In Production, it typically runs in a cluster of an odd number of nodes, higher than 3.
  3. Uses redundancy to allow failures and stay functional.

Features and Benefits

  1. ZooKeeper allows distributed processes to coordinate with each other through a shared hierarchal namespace which is organized similarly to a standard file system and keeps data in-memory
  2. ZooKeeper is replicated solution and it allows clients connect to a single ZooKeeper server. The client maintains a TCP connection, through which it sends requests, gets responses, gets watch events, and sends heart beats.
  3. Zookeeper manages the following
    1. Sequential Consistency: Updates from a client will be applied in the order that they were sent.
    2. Atomicity: Updates either succeed or fail. No partial results.
    3. Single System Image: A client will see the same view of the service regardless of the server that it connects to.
    4. Reliability: Once an update has been applied, it will persist from that time forward until a client overwrites the update.
    5. Timeliness: The client’s view of the system is guaranteed to be up-to-date within a certain time bound (configured unit of order of seconds).
    6. Note: Default configurations would be used as recommended by Zookeeper.
  4. In case of failure, Zookeeper uses FastLeaderElection algorithm and maintains the reliability. The leader election algorithm allows for the system to recover fast enough preventing throughput from dropping substantially. As per ZooKeeper documentation, it takes less than 200ms to elect a new leader.
  5. Security
    1. ZooKeeper now supports Kerberos security
    2. Authorization is done via ACLs
    3. Supports several types of restrictions
    4. Message digest
    5. Hostname
    6. IP address
    7. Can limit access by function
    8. Read, write, delete, etc.

Distributed systems with Zookeeper

Instead of making the nodes in a cluster communicate directly with each other to coordinate the work, the nodes will communicate with the Zookeeper server instead.

Data model

It looks a lot like a tree and very similar to a file system.

  1. Each element in the tree or file system is called Znode.
    1. Properties of a Znode
      1. Hybrid between a file and a directory.
      2. Znodes can store any data inside (like a file)
      3. Znodes can have children znodes (like a directory)
    2. Types of a Znode
      1. Persistent - persists between sessions. e.g. if our application disconnects from the zookeeper, and then reconnects again, a persistent znode that was created by our application stays intact with all it’s children and data.
      2. Ephemeral - is deleted when the session ends. Lets us identify if the node that created a znode is now dead.
  2. Zookeeper manages information as a hierarchical system of nodes (much like a file system). Each node can contain data or can contain child nodes.
  3. ZooKeeper models a hierarchical filesystem
  4. A znode may contain data and/or other znodes

References

  1. https://zookeeper.apache.org/
  2. Zookeeper wiki: https://cwiki.apache.org/confluence/display/ZOOKEEPER/Index
  3. ZooKeeper Recipes and Solutions: https://zookeeper.apache.org/doc/current/recipes.html
  4. The Tao of ZooKeeper: https://cwiki.apache.org/confluence/display/ZOOKEEPER/Tao

TODO

  1. https://highscalability.com/zookeeper-a-reliable-scalable-distributed-coordination-syste/

Use cases

  1. Distributed locking
  2. Locking for coordination among threads
    1. Imagine a multithreaded program where a lock is needed to coordinate among threads.
    2. Usage of the java.util.concurrent package is the first and most feasible solution most developers opt for - but how will we handle it when there is a need to scale up the application?
    3. The problem gets bigger when the locking needs to be handled across requests coming from different networks and machines.
    4. This is where we can use Apache Zooper.

Used by

Popular technology used by many companies and projects (Kafka, Hadoop, HBase, etc.)

References

  1. https://www.linkedin.com/pulse/how-implement-zookeeper-locking-mechanism-minal-bagade/

Tags

  1. Zookeeper Locks
  2. kafka and zookeeper
  3. Zookeeper Installation, Configuration and Tooling
  4. Zookeeper Client Threading Model
  5. Zookeeper Java API
  6. Zookeeper - Watchers, Triggers and Failure Detection
  7. Zookeeper - Debugging applications