Integration / Apache Kafka Interview questions
How do you migrate a Kafka cluster from ZooKeeper mode to KRaft mode?
Since Apache Kafka 4.0 removed ZooKeeper mode entirely, any cluster still running on it must migrate to KRaft before upgrading to 4.0 or later — there is no direct ZooKeeper-to-4.0 upgrade path. The supported migration runs on a 3.x release that still supports both modes, moving the cluster over while it stays online.
- Upgrade to a 3.x release that supports migration (Kafka recommends being on a recent 3.x, e.g. 3.9.x, before starting) if not already there.
- Deploy a new KRaft controller quorum alongside the existing ZooKeeper ensemble, configured in migration mode rather than replacing anything yet.
- Enable migration on the brokers (
zookeeper.metadata.migration.enable=true), which starts syncing existing cluster metadata from ZooKeeper into the new KRaft controllers. - Verify the migration has completed and the KRaft controllers hold a full, correct copy of cluster metadata before proceeding further.
- Roll the brokers one at a time to run in KRaft mode instead of ZooKeeper mode, removing their ZooKeeper dependency broker by broker.
- Decommission the ZooKeeper ensemble once every broker has been confirmed running purely on KRaft.
- Only then upgrade to Kafka 4.0+, which requires the cluster to already be fully on KRaft.
The whole process is designed to run without cluster downtime, but it's a multi-step, order-sensitive migration rather than a simple version bump, which is why Kafka's own documentation strongly recommends testing the full sequence against a non-production cluster first.
More Related questions...