Is Zookeeper a must for Kafka?

PartitioningApache ZookeeperProducer ConsumerApache KafkaBroker

Partitioning Problem Overview


In Kafka, I would like to use only a single broker, single topic and a single partition having one producer and multiple consumers (each consumer getting its own copy of data from the broker). Given this, I do not want the overhead of using Zookeeper; Can I not just use the broker only? Why is a Zookeeper must?

Partitioning Solutions


Solution 1 - Partitioning

Yes, Zookeeper is required for running Kafka. From the Kafka Getting Started documentation:

> Step 2: Start the server > > Kafka uses zookeeper so you need to first start a zookeeper server if > you don't already have one. You can use the convenience script > packaged with kafka to get a quick-and-dirty single-node zookeeper > instance.

As to why, well people long ago discovered that you need to have some way to coordinating tasks, state management, configuration, etc across a distributed system. Some projects have built their own mechanisms (think of the configuration server in a MongoDB sharded cluster, or a Master node in an Elasticsearch cluster). Others have chosen to take advantage of Zookeeper as a general purpose distributed process coordination system. So Kafka, Storm, HBase, SolrCloud to just name a few all use Zookeeper to help manage and coordinate.

Kafka is a distributed system and is built to use Zookeeper. The fact that you are not using any of the distributed features of Kafka does not change how it was built. In any event there should not be much overhead from using Zookeeper. A bigger question is why you would use this particular design pattern -- a single broker implementation of Kafka misses out on all of the reliability features of a multi-broker cluster along with its ability to scale.

Solution 2 - Partitioning

As explained by others, Kafka (even in most recent version) will not work without Zookeeper.

Kafka uses Zookeeper for the following:

Electing a controller. The controller is one of the brokers and is responsible for maintaining the leader/follower relationship for all the partitions. When a node shuts down, it is the controller that tells other replicas to become partition leaders to replace the partition leaders on the node that is going away. Zookeeper is used to elect a controller, make sure there is only one and elect a new one it if it crashes.

Cluster membership - which brokers are alive and part of the cluster? this is also managed through ZooKeeper.

Topic configuration - which topics exist, how many partitions each has, where are the replicas, who is the preferred leader, what configuration overrides are set for each topic

(0.9.0) - Quotas - how much data is each client allowed to read and write

(0.9.0) - ACLs - who is allowed to read and write to which topic (old high level consumer) - Which consumer groups exist, who are their members and what is the latest offset each group got from each partition.

[from https://www.quora.com/What-is-the-actual-role-of-ZooKeeper-in-Kafka/answer/Gwen-Shapira]

Regarding your scenario, only one broker instance and one producer with multiple consumer, u can use pusher to create a channel, and push event to that channel that consumer can subscribe to and hand those events. https://pusher.com/

Solution 3 - Partitioning

Important update - August 2019:

ZooKeeper dependency will be removed from Apache Kafka. See the high-level discussion in KIP-500: Replace ZooKeeper with a Self-Managed Metadata Quorum.

These efforts will take a few Kafka releases and additional KIPs. Kafka Controllers will take over the tasks of current ZooKeeper tasks. The Controllers will leverage the benefits of the Event Log which is a core concept of Kafka.

Some benefits of the new Kafka architecture are a simpler architecture, ease of operations, and better scalability e.g. allow "unlimited partitions".

Solution 4 - Partitioning

Updated on Feb 2021

For the latest version (2.7.0) ZooKeeper is still required for running Kafka, but in the near future ZooKeeper will be replaced with a Self-Managed Metadata Quorum.

See details in the accepted KIP-500.


a busy cat

1. Current status

Kafka uses ZooKeeper to store its metadata about partitions and brokers, and to elect a broker to be the Kafka Controller.

Currently, removing this dependency on ZooKeeper is work in progress (through the KIP-500) .

2. Profit of removal

Removing the Apache ZooKeeper dependency provides three distinct benefits:

  • First, it simplifies the architecture by consolidating metadata in Kafka itself, rather than splitting it between Kafka and ZooKeeper. This improves stability, simplifies the software, and makes it easier to monitor, administer, and support Kafka.
  • Second, it improves control plane performance, enabling clusters to scale to millions of partitions.
  • Finally, it allows Kafka to have a single security model for the whole system, rather than having one for Kafka and one for Zookeeper.

3. Roadmap

ZooKeeper removal is expected in 2021 and has some milestones which are represented in the following KIPs:

|   KIP   |                           Name                           |      Status      | Fix Version/s |
|:-------:|:--------------------------------------------------------:|:----------------:|---------------|
| KIP-455 | Create an Administrative API for Replica Reassignment    |     Accepted     | 2.6.0         |
| KIP-497 | Add inter-broker API to alter ISR                        |     Accepted     | 2.7.0         |
| KIP-543 | Expand ConfigCommand's non-ZK functionality              |     Accepted     | 2.6.0         |
| KIP-555 | Deprecate Direct ZK access in Kafka Administrative Tools |     Accepted     | None          |
| KIP-589 | Add API to update Replica state in Controller            |     Accepted     | 2.8.0         |
| KIP-590 | Redirect Zookeeper Mutation Protocols to The Controller  |     Accepted     | 2.8.0         |
| KIP-595 | A Raft Protocol for the Metadata Quorum                  |     Accepted     | None          |
| KIP-631 | The Quorum-based Kafka Controller                        | Under discussion | None          |

KIP-500 introduced the concept of a bridge release that can coexist with both pre- and post-KIP-500 versions of Kafka. Bridge releases are important because they enable zero-downtime upgrades to the post-ZooKeeper world.

References:

  1. KIP-500: Replace ZooKeeper with a Self-Managed Metadata Quorum
  2. Apache Kafka Needs No Keeper: Removing the Apache ZooKeeper Dependency
  3. Preparing Your Clients and Tools for KIP-500: ZooKeeper Removal from Apache Kafka

Solution 5 - Partitioning

IMHO Zookeeper is not an overhead but makes your life a lot easier.

It is basically used to maintain co-ordination between different nodes in a cluster. One of the most important things for Kafka is it uses zookeeper to periodically commit offsets so that in case of node failure it can resume from the previously committed offset (imagine yourself taking care of all this by your own).

Zookeeper also plays a vital role for serving many other purposes, such as leader detection, configuration management, synchronization, detecting when a new node joins or leaves the cluster, etc.

Future Kafka releases are planning to remove the zookeeper dependency but as of now it is an integral part of it.

Here are a few lines taken from their FAQ page:

> Once the Zookeeper quorum is down, brokers could result in a bad state and could not normally serve client requests, etc. Although when Zookeeper quorum recovers, the Kafka brokers should be able to resume to normal state automatically, there are still a few corner cases the they cannot and a hard kill-and-recovery is required to bring it back to normal. Hence it is recommended to closely monitor your zookeeper cluster and provision it so that it is performant.

For more details check here

Solution 6 - Partitioning

Kafka is built to use Zookeeper. There is no escaping from that.

Kafka is a distributed system and uses Zookeeper to track status of kafka cluster nodes. It also keeps track of Kafka topics, partitions etc.

Looking at your question, it seems you do not need Kafka. You can use any application that supports pub-sub such as Redis, Rabbit MQ or hosted solutions such as Pub-nub.

Solution 7 - Partitioning

Zookeeper is centralizing and management system for any kind of distributed systems. Distributed system is different software modules running on different nodes/clusters (might be on geographically distant locations) but running as one system. Zookeeper facilitates communication between the nodes, sharing configurations among the nodes, it keeps track of which node is leader, which node joins/leaves, etc. Zookeeper is the one who keeps distributed systems sane and maintains consistency. Zookeeper basically is an orchestration platform.

Kafka is a distributed system. And hence it needs some kind of orchestration for its nodes that might be geographically distant (or not).

Solution 8 - Partitioning

Apache Kafka v2.8.0 gives you early access to KIP-500 that removes the Zookeeper dependency on Kafka which means it no longer requires Apache Zookeeper.


Instead, Kafka can now run in Kafka Raft metadata mode (KRaft mode) which enables an internal Raft quorum. When Kafka runs in KRaft mode its metadata is no longer stored on ZooKeeper but on this internal quorum of controller nodes instead. This means that you don't even have to run ZooKeeper at all any longer.

Note however that v2.8.0 is currently early access and you should not use Zookeeper-less Kafka in production for the time being.


A few benefits of removing ZooKeeper dependency and replacing it with an internal quorum:

  • More efficient as controllers no longer need to communicate with ZooKeeper to fetch cluster state metadata every time the cluster is starting up or when a controller election is being made
  • More scalable as the new implementation will be able to support many more topics and partitions in KRaft mode
  • Easier cluster management and configuration as you don't have to manage two distinct services any longer
  • Single process Kafka Cluster

For more details you can read the article Kafka No Longer Requires ZooKeeper

Solution 9 - Partitioning

Other than the usual payload message transfer, there are many other communications that happens in kafka, like

  • Events related to brokers requesting the cluster membership.
  • Events related to Brokers becoming available.
  • Getting bootstrap config setups.
  • Events related to controller and leader updates.
  • Help status updates like Heartbeat updates.

Zookeeper itself is a distributed system consisting of multiple nodes in an ensemble. Zookeeper is centralised service for maintaining such metadata.

Solution 10 - Partitioning

Yes, Zookeeper is must by design for Kafka. Because Zookeeper has the responsibility a kind of managing Kafka cluster. It has list of all Kafka brokers with it. It notifies Kafka, if any broker goes down, or partition goes down or new broker is up or partition is up. In short ZK keeps every Kafka broker updated about current state of the Kafka cluster.

Then every Kafka client(producer/consumer) all need to do is connect with any single broker and that broker has all metadata updated by Zookeeper, so client need not to bother about broker discovery headache.

Solution 11 - Partitioning

This article explains the role of Zookeeper in Kafka. It explains how kafka is stateless and how zookeper plays an important role in distributed nature of kafka (and many more distributed systems).

Solution 12 - Partitioning

The request to run Kafka without Zookeeper seems to be quite common. The library Charlatan addresses this.

According to the description is Charlatan more or less a mock for Zookeeper, providing the Zookeeper services either backed up by other tools or by a database.

I encountered that library when dealing with the main product of the authors for the Charlatan library; there it works fine …

Solution 13 - Partitioning

> Firstly

Apache ZooKeeper is a distributed store which is used to provide configuration and synchronization services in a high available way. In more recent versions of Kafka, work was done in order for the client consumers to not store information about how far it had consumed messages (called offsets) into ZooKeeper.This reduced usage did not get rid of the need for consensus and coordination in distributed systems however. While Kafka provides fault-tolerance and resilience, something is needed in order to provide the coordination needed and ZooKeeper enables that piece of the overall system.

> Secondly

Agreeing on who the leader of a partition is, is one example of the practical application of ZooKeeper within the Kafka ecosystem.

Zookeeper would work if there was even a single broker. 

These are from Kafka In Action book. Image is from this course

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPaajiView Question on Stackoverflow
Solution 1 - PartitioningJohn PetroneView Answer on Stackoverflow
Solution 2 - PartitioningKevin LiView Answer on Stackoverflow
Solution 3 - PartitioningKai WähnerView Answer on Stackoverflow
Solution 4 - PartitioningIskuskov AlexanderView Answer on Stackoverflow
Solution 5 - Partitioninguser2720864View Answer on Stackoverflow
Solution 6 - PartitioningSantosh RoutView Answer on Stackoverflow
Solution 7 - PartitioningShreeView Answer on Stackoverflow
Solution 8 - PartitioningGiorgos MyrianthousView Answer on Stackoverflow
Solution 9 - PartitioningAmulya HollaView Answer on Stackoverflow
Solution 10 - PartitioningCPATIL9767View Answer on Stackoverflow
Solution 11 - PartitioningJ. PView Answer on Stackoverflow
Solution 12 - PartitioningtquadratView Answer on Stackoverflow
Solution 13 - PartitioningfgulView Answer on Stackoverflow