leo.blog();

ZooKeeper protocol

ZooKeeper is commonly used as a distributed key-value store. A lot of systems use it for storing configuration, doing service discovery, or for doing distributed locking.

This page aims to document the network protocol used by Zookeeper clients to talk to Zookeeper nodes.

Ports

ServiceProtocolPort
ZookeeperTCP2181
ClickHouse KeeperTCP9181

Protocol notes

When the client connects, it learns a session ID, which seems to be incremented by 1 for each new connection. So the server must be keeping track of the last session ID it gave out.

Integers are big-endian.

Message types

OpcodeNameDescription
N/AHandshakeTo establish a connection
1CreateCreate a node

Handshake

On connecting to a Zookeeper node, the client sends a handshake request packet. In return, the server responds with a handshake response packet.

These handshake packets are slightly different from all the other packets in that they do not contain the xid and packet type fields.

Client -> Server

LengthNameDescription
4LengthLength of the remaining packet
4Protocol versionProtocol version number, always 0
4Last seen zxidLast seen zxid

blah blah blah

Server -> Client

blah blah blah

Some useful resources

Leave a Comment