Skip to main content
XenonStack

Enterprise Data Management

XenonStack Insights Kafka and ZooKeeper Architecture: KRaft Explained

and | Published | Updated

Kafka and ZooKeeper Architecture: KRaft Explained
11:17
Kafka and ZooKeeper Architecture: governed event streams, KRaft controller quorum, partitions and replicas, brokers and topics

Key takeaway

  • Kafka and ZooKeeper architecture explained: brokers, partitions, replicas, the controller, KRaft and the Kafka 4.0 ZooKeeper removal, with a migration plan

Apache Kafka stores events in partitioned, replicated logs, and it needs a place to keep cluster metadata and elect a controller. Until Kafka 3.x, that place was an external ZooKeeper ensemble. Kafka 4.0, announced on 18 March 2025, is described by the project as the first major release to operate entirely without ZooKeeper. Metadata now lives in Kafka itself, managed by a controller quorum running the KRaft protocol.

This guide takes the Kafka side of the story: what the broker, partition and replica model is, what ZooKeeper used to do for it, how KRaft replaces it, and how to plan the move. For ZooKeeper as a coordination service in its own right, including its security and installation, read our companion guide to Apache ZooKeeper.

How does Kafka store and serve events?

Kafka keeps events in topics, and each topic is split across brokers into partitions. Each new event is appended to one partition. According to the Kafka 4.0 introduction, events with the same key land in the same partition, and a consumer reads a partition's events in exactly the order they were written. Ordering is therefore guaranteed per partition, not across a whole topic.

Two-column diagram mapping ZooKeeper-era duties (external metadata, controller election, pushed updates, two systems) to KRaft equivalents (metadata log, Raft quorum, broker fetch, one system)

Partitions, offsets and consumer groups

A consumer's position in a partition is a single integer, the offset of the next message to consume, as the Kafka design documentation puts it. Each partition is consumed by exactly one consumer within each subscribing consumer group at any given time, so the number of partitions caps how far a consumer group can scale out. Consumers can rewind to an earlier offset and read data again, because events are not deleted when read; retention is set per topic.

Replication, leaders and the ISR

The unit of replication is the topic partition. Each partition normally has one leader and zero or more followers. Writes go to the leader and followers pull from it like ordinary consumers. The leader tracks the set of in-sync replicas (the ISR), and a message counts as committed when all replicas in the ISR have applied it. Topics also carry a min.insync.replicas setting that is checked for writes sent with acks=all. The introduction notes that a common production setting is a replication factor of 3.

Partition leadership, topic configuration and broker membership are metadata. Someone has to hold that metadata and decide which broker leads which partition. That is the controller's job, and it is the point where ZooKeeper and KRaft differ.

1. Inventory: List clusters, broker, client and Java versions, and which run in ZooKeeper mode
2. Check: Check client and Java prerequisites against the 4.0 announcement
3. Bridge: Upgrade to 3.9 and rehearse the migration in a non-production cluster
4. Size quorum: Size the controller quorum as 2N + 1 and keep controllers dedicated in production
5. Move: Move to 4.0.x or later, then retire ZooKeeper and update runbooks and access controls
Diagram: planning the ZooKeeper to KRaft move (flow view)

What did ZooKeeper do for Kafka before KRaft?

In the design proposal that started the change, KIP-500, the Kafka community states that Kafka relied on ZooKeeper to store partition and broker metadata and to elect the Kafka controller. The same proposal lists the problems this caused: ZooKeeper state and the controller's in-memory state could diverge, brokers could miss some controller updates, and running two systems made setup and security configuration harder.

How ZooKeeper itself works

The ZooKeeper overview describes a distributed, open-source coordination service. Its namespace is a hierarchy of data registers called znodes, and each znode can hold data and have children. The service is replicated across a set of hosts called an ensemble and stays available while a majority of servers are up. A client connects to one server. Reads are served from that server's local replica, while all write requests are forwarded to a single server called the leader, with the other servers acting as followers. Ephemeral znodes are deleted when the session that created them ends, and clients can set watches that fire when a znode changes.

How does KRaft replace ZooKeeper?

KIP-500 moves metadata into Kafka itself. Brokers consume metadata events from an ordered log instead of receiving pushed notifications that can arrive incompletely. Three or more controller nodes form a Raft quorum that manages the metadata log. The leader of that log is called the active controller, and the other controllers act as hot standbys. Brokers fetch metadata updates from the active controller and cache them locally. The proposal expects this to support more partitions with less CPU use and to avoid a long reload when a new active controller takes over. These are design goals stated in the proposal, so measure them in your own environment before relying on them.

The KRaft operations documentation sets out the practical model:

  • A server's role is set with process.roles: controller, broker, or broker,controller.
  • Servers selected as controllers take part in the metadata quorum, and every broker and controller must set controller.quorum.bootstrap.servers.
  • Servers that act as both broker and controller are called combined servers. The documentation says combined mode is not recommended in critical deployment environments, because controllers cannot be rolled or scaled separately from brokers. It is simpler for small cases such as development.
  • For redundancy, use three or more controllers. Admins typically select 3 or 5, and to withstand N concurrent failures the controller cluster must include 2N + 1 controllers.

What is the status of ZooKeeper in Kafka today?

The Kafka 4.0 upgrade notes state that Kafka 4.0 supports only KRaft mode and that ZooKeeper mode has been removed. Clusters in ZooKeeper mode have to be migrated to KRaft before they can be upgraded to 4.0.x. The KRaft documentation adds that migration from ZooKeeper needs a bridge release, and that the last bridge release is Kafka 3.9. The 4.0 announcement also says brokers should be version 2.1 or higher before upgrading Java clients, that Kafka clients and Streams need Java 11, and that brokers, Connect and tools need Java 17. The project's release list now shows versions later than 4.0, so confirm the current release and its notes on kafka.apache.org before planning.

Your situationWhat to doStatus
New clusterStart in KRaft mode with dedicated controllers for productionSupported path in 4.0 and later
ZooKeeper cluster on a version before 3.9Upgrade to 3.9, then follow the documented ZooKeeper to KRaft migration3.9 is the last bridge release
ZooKeeper cluster on 3.9Run the ZooKeeper to KRaft migration, then move to 4.0.xZooKeeper mode is removed in 4.0
Existing KRaft cluster older than 3.3Upgrade to 3.9.x before 4.0.xRecommended in the 4.0 upgrade notes
Development or small test setupCombined mode is acceptableNot recommended for critical environments

How should an enterprise plan the move to KRaft?

  1. Inventory clusters, broker versions, client versions and Java versions. Note which clusters still run in ZooKeeper mode.
  2. Check client and Java prerequisites against the 4.0 announcement before touching brokers.
  3. Upgrade to the 3.9 bridge release, rehearse the migration in a non-production cluster, and confirm the procedure in the migration section of the Kafka documentation for your version.
  4. Size the controller quorum for the failures you must survive (2N + 1) and keep controllers dedicated in production.
  5. Move to 4.0.x or later, then retire the ZooKeeper ensemble and update runbooks, monitoring and access controls.

When not to rush: a stable cluster on 3.9 with no near-term need for 4.0 features can schedule the migration, but should not leave it open-ended, because ZooKeeper mode is gone from 4.0 onwards. The trade-off to weigh is a one-off migration effort against running two coordination systems indefinitely.

Why does the streaming layer matter for governed AI?

Kafka topics often carry the events that downstream analytics and AI agents act on. If the controller layer is unstable, every consumer is affected, so metadata design is an operational risk decision as well as a technical one. For how event streams feed decisions, see our guide to real-time intelligence, and for streaming platform choices see Kafka vs Pulsar. Agents that react to events need governed context and traceable decisions; our overview of agentic workflows covers the patterns. ElixirData keeps governed context, versioned policy and decision traces in one decision layer above AI agents, and AgentAnalyst lets teams ask questions of enterprise data in plain language and get real-time insights. For running Kafka on Kubernetes, start with Kubernetes architecture and components.

To map one streaming decision your agents should make, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

Does Kafka still need ZooKeeper?

Not from Kafka 4.0. The 4.0 release announcement describes it as the first major release to operate entirely without ZooKeeper, and the upgrade notes say ZooKeeper mode has been removed. Clusters in ZooKeeper mode must be migrated to KRaft before upgrading to 4.0.x.

What replaced ZooKeeper in Kafka?

KRaft. Metadata is stored in an ordered log managed by a Raft quorum of controller nodes, with one active controller and hot standbys. Brokers fetch metadata updates from the active controller.

What does a Kafka controller do?

According to KIP-500, ZooKeeper was used to store partition and broker metadata and to elect the Kafka controller. With KRaft, the controller quorum holds that metadata in the cluster metadata log and the active controller leads it.

How many controllers should a KRaft cluster have?

The Kafka documentation says to use three or more controllers for redundancy, typically 3 or 5. To withstand N concurrent failures you need 2N + 1 controllers.

Is combined broker and controller mode safe for production?

The documentation says combined mode is not recommended in critical deployment environments, because controllers cannot be rolled or scaled separately from brokers. It suits development and small use cases.

How do I migrate from ZooKeeper to KRaft?

Use a bridge release. The documentation says the last bridge release is Kafka 3.9. Upgrade to 3.9, follow the migration procedure in the documentation for your version, then move to 4.0.x.

Ready to put AI agents to work? See an ElixirClaw demo: the agentic OS to build, orchestrate and govern AI agents across your enterprise systems.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in solving your challenges with the XenonStack team?
Get Started

Tell us about you and your priorities so we can prepare the right conversation. It takes about 2 minutes.

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Continue