Is Zookeeper a must for Kafka?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Historically, ZooKeeper has been a critical component of Kafka, responsible for managing the distributed system’s coordination tasks, such as leader election, metadata storage, and configuration management. However, with newer Kafka versions, particularly from Kafka 2.8 onwards, ZooKeeper is no longer required due to the introduction of the KRaft (Kafka Raft) consensus protocol.
Here’s a breakdown of when and why ZooKeeper is or isn’t needed:
When ZooKeeper Is Required
- Kafka Versions Below 2.8:
- Kafka depends on ZooKeeper for critical tasks such as:
- Leader Election: ZooKeeper determines which broker will be the leader for each topic partition.
- Metadata Storage: ZooKeeper stores information about brokers, topics, and partitions.
- Configuration Management: ZooKeeper manages broker configurations and their updates.
- In these versions, Kafka cannot function without ZooKeeper.
- Advantages of Using ZooKeeper:
- Decouples metadata management from Kafka brokers.
- Ensures a robust consensus algorithm for leader election.
When ZooKeeper Is Not Required
- Kafka Versions 2.8 and Above (KRaft Mode):
- Kafka introduced the KRaft (Kafka Raft) protocol, which removes the dependency on ZooKeeper.
- KRaft Mode:
- Kafka brokers use the Raft consensus algorithm for metadata management and leader election.
- One or more brokers act as the controllers, eliminating the need for an external ZooKeeper cluster.
- The metadata is stored directly within Kafka, simplifying deployment and operations.
- Advantages of KRaft Mode:
- Simplified Architecture:
- No need for a separate ZooKeeper cluster.
- Easier deployment and maintenance.
- Improved Scalability:
- Handles larger clusters and higher metadata update rates.
- Higher Performance:
- Direct communication between brokers without the latency introduced by ZooKeeper.
- Unified Security:
- Only Kafka’s security mechanisms (e.g., SASL, ACLs) need to be managed.
Migration from ZooKeeper to KRaft
- Kafka 2.8 and 3.x:
- Kafka operates in either ZooKeeper mode or KRaft mode.
- To migrate:
- Upgrade Kafka to a version supporting KRaft.
- Gradually migrate metadata from ZooKeeper to KRaft using Kafka tools.
- After migration, ZooKeeper can be retired.
- Kafka 4.0 and Above:
- Kafka will operate only in KRaft mode, completely deprecating ZooKeeper.
ZooKeeper vs. KRaft: A Comparison
| Feature | ZooKeeper Mode | KRaft Mode |
| Metadata Management | External (ZooKeeper) | Internal (Kafka controllers) |
| Deployment | Requires separate ZooKeeper cluster | Simplified, no ZooKeeper required |
| Scalability | Limited by ZooKeeper's scalability | Higher scalability with Raft consensus |
| Performance | Additional latency due to ZooKeeper | Lower latency with internal metadata storage |
| Security | Requires ZooKeeper security setup | Unified Kafka security |
| Kafka Version Support | Kafka < 2.8 | Kafka 2.8+ (optional), 4.0+ (mandatory) |
Key Considerations
- Legacy Clusters:
- If your Kafka version is below 2.8, ZooKeeper is still a hard requirement.
- For older clusters, ensure ZooKeeper is set up with proper redundancy (e.g., a 3 or 5-node ZooKeeper ensemble).
- New Deployments:
- For Kafka 2.8+ and newer, it is recommended to use KRaft mode to avoid the operational overhead of managing ZooKeeper.
- Future Proofing:
- Since ZooKeeper will be completely deprecated in Kafka 4.0, planning a migration to KRaft mode is a good long-term strategy.
Conclusion
- ZooKeeper is not mandatory for Kafka versions 2.8 and above running in KRaft mode.
- For older versions or clusters not yet migrated, ZooKeeper remains essential.
- Moving to KRaft simplifies the architecture, improves performance, and aligns with Kafka’s future roadmap.
Related reading
- Is key required as part of sending messages to Kafka?
- Is there a way to delete all the data from a topic or delete the topic before every run?
- Is there a way to purge the topic in Kafka?
- Java, How to get number of messages in a topic in apache kafka
- Kafka: Consumer API vs Streams API
- Leader Not Available Kafka in Console Producer
- Understanding Kafka Topics and Partitions
- Using Kafka as a (CQRS) Eventstore. Good idea?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.