Apache Kafka Tutorial 0/111 lessons ~6 min read Lesson 13
ZooKeeper vs KRaft
What is ZooKeeper vs KRaft?
Course progress0%
Focus
9 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
What is ZooKeeper vs KRaft? Older Kafka clusters used ZooKeeper for metadata coordination.
Understanding the topic
What happens — ZooKeeper vs KRaft:
- Old clusters used ZooKeeper for metadata.
- KRaft embeds metadata in Kafka itself.
- Controller quorum manages leaders.
- New deployments should use KRaft.
| Term | Description |
|---|---|
| KRaft | Kafka Raft metadata mode. |
| Controller quorum | Dedicated controller brokers. |
| ZooKeeper | Legacy external coordination. |
| __cluster_metadata | Internal metadata topic. |
Visual explanation
Pipeline view:
text
Producer↓Topic partition log↓Consumer group A↓Consumer group BReplay is possible because records are retained
Step-by-step explanation
- Elect controller — Raft consensus.
- Store metadata — Topics, partitions, ACLs.
- Notify brokers — Leader changes.
- Migrate — ZK → KRaft upgrade path.
Informative example
Example:
bash
kafka-topics --bootstrap-server localhost:9092 --create --topic zookeeper-vs-kraft --partitions 6 --replication-factor 3kafka-console-producer --bootstrap-server localhost:9092 --topic zookeeper-vs-kraftkafka-console-consumer --bootstrap-server localhost:9092 --topic zookeeper-vs-kraft --from-beginningkafka-consumer-groups --bootstrap-server localhost:9092 --describe --group zookeeper-vs-kraft-service
Execution workflow
1ZooKeeper vs KRaft workflow
1 / 4Elect controller
Raft consensus.
Best practices
- Design events around business facts: OrderCreated, PaymentAuthorized, InventoryReserved.
- Pick keys based on ordering and load distribution.
- Document owner, retention, schema, partitions, and consumers for every topic.
- Assume duplicate delivery and build idempotent consumers early.
Common mistakes
- Expecting global ordering across a topic.
- Creating one partition because local demos work.
- Skipping schema governance until multiple teams deploy independently.
Summary
ZooKeeper vs KRaft — Start every design with event ownership, topic naming, key choice, schema contract, retention, replay plan, and monitoring.
Ready to mark this lesson complete?Track your journey across the entire course.