9 Managing Kafka within the enterprise
As a prototype nears production, managing Kafka becomes an exercise in operationalizing the control plane, choosing a deployment model, and making security enforceable end to end. The chapter frames Kafka as two planes: brokers form the data plane that moves records, while the controller quorum runs the control plane that governs metadata, leadership, and cluster state. It then compares on‑premises, cloud, and hybrid deployments through the lenses of latency, cost, operability, and compliance, and closes the loop with actionable guidance on authentication, authorization, encryption in motion and at rest, and the practicalities of hardening an enterprise rollout.
The heart of operational Kafka is KRaft: a quorum of controllers that stores cluster metadata in a Raft log, elects a leader, commits updates with a majority, and keeps fast access via snapshots and in‑memory caches. Brokers forward admin changes to the leader, heartbeat for liveness, and fetch committed metadata; on failures, Raft elections and ISR‑based leader reassignments keep the cluster consistent, with quorum sizing following the 2N+1 rule and strong incentives to span three sites for data center resilience. The chapter walks through essential configuration (roles, node IDs, listeners, voters) and contrasts KRaft with the legacy ZooKeeper model, explaining why Kafka is consolidating metadata management to simplify operations, accelerate recovery, and streamline propagation.
Deployment trade‑offs are treated candidly: on‑prem offers control and cost tuning but demands deep operational skills; managed cloud offloads toil but introduces limits and potential lock‑in; multi‑region is easier in cloud yet adds latency and networking costs; and scaling a stateful system means planned rebalancing, not effortless autoscale. Hybrid patterns dominate in practice—separate clusters synchronized by replication, or bridging on‑prem to cloud with Kafka Connect and selective data movement—each with clear cost, latency, and reliability implications. Security guidance is prescriptive: use TLS/mTLS where exposure exists, choose SASL mechanisms appropriately, integrate with enterprise identity (e.g., OAuth/OIDC), define ACLs carefully beyond read/write, protect secrets, and address data at rest via disk encryption or end‑to‑end encryption (client‑side or via a proxy). The overarching message is to define policies early, document all network paths, and align placement, capacity, and security so Kafka remains resilient and compliant at enterprise scale.
Controllers operate as a quorum, responsible for storing metadata and monitoring cluster health.
Metadata updates are sent to the leader controller, which appends each update to its log. Follower controllers fetch these updates from the leader, and once a majority have replicated the update, it is marked as committed.
In the event of a complete data center outage, losing the majority of controllers causes a loss of quorum if the cluster is distributed across two data centers. However, with three data centers, quorum can still be maintained despite the failure of an entire data center. In this case, N = 1, meaning the system can tolerate only one node failure.
Metadata records are written to the metadata log. Periodic snapshots capture the latest committed state, which is also maintained in an in-memory cache for rapid access.
Clients send metadata requests to brokers and receive responses containing the current cluster metadata. Brokers forward client-initiated metadata changes to the leader controller and periodically fetch updated metadata. Brokers also send heartbeats to the controller, which uses them to track broker liveness.
Various types of communication within a Kafka cluster using ZooKeeper
Replicating data from a local Kafka cluster to a Kafka cluster in the cloud
Bringing data from local Kafka cluster to the cloud with the help of Kafka Connect
Bringing data to the cloud cluster with Kafka connect or directly
Overview of the security features supported in Kafka
Generating keys and receiving a certificate. The Party (client or server) is the entity that generates the key pair and requests a signed certificate from the certificate authority.
Implementing end-to-end encryption with the encryption and decryption of messages done on the clients.
Using a proxy for encrypting and decrypting messages.
Summary
- Kafka clusters consist of brokers (handling message storage and retrieval) and controllers (managing metadata and cluster coordination). This means that brokers are responsible for storing and serving data, while controllers ensure the cluster remains operational by managing leadership elections and metadata updates. Understanding how brokers and controllers work together guides your sizing, HA topology, security rules, monitoring, and incident playbooks.
- Metadata storage is managed in Raft logs (KRaft mode) or via ZooKeeper (legacy mode). So, controllers handle leader elections, partition assignments, ACLs, consumer groups, and transaction states.
- Controllers use quorum-based decision-making, which ensures fault tolerance. To tolerate N controller failures, you run 2N + 1 controllers so that a majority quorum of N + 1 controllers is still available; otherwise, leader elections and metadata changes halt.
- The Kafka ecosystem can be deployed on-premises or in the cloud as a managed service. While on-premises deployments offer full control and compliance, managed services help reduce operational burden but come with the risk of vendor lock-in and limited customization.
- Many organizations operate dual Kafka clusters (on-premises and in the cloud) using MirrorMaker or Kafka Connect for data synchronization. This approach enhances resilience and disaster recovery, while also enabling hybrid architectures, but it introduces additional complexity, potential latency, and synchronization overhead.
- Security in Kafka is divided into three key areas: authentication (verifying identities using mTLS or SASL), authorization (enforcing access controls via ACLs), and encryption (secure communication with TLS). Do all three—together—to secure your Kafka deployment.
- Kafka natively encrypts only data in transit, not at rest. Options for protecting stored data are filesystem encryption (Linux LUKS, cloud storage encryption) or end-to-end encryption.
- Permissions in Kafka are enforced at the topic level, which introduces a notable restriction. Once a client is granted access to a topic, it can freely read or write all data within that topic without granular control over specific messages or partitions.
FAQ
What’s the difference between Kafka’s data plane and control plane, and which roles handle each?
The data plane moves and stores records; brokers handle produce/consume, replication, and serving data. The control plane manages cluster metadata and coordination; KRaft controllers store and replicate metadata, elect leaders, track broker liveness, and orchestrate partition leadership. In production, dedicate controller nodes to reduce latency and avoid metadata unavailability.How do KRaft controllers store and replicate metadata reliably?
Controllers write all metadata changes to a Raft log (conceptually referred to as__cluster_metadata). The leader appends updates; followers fetch and append them. An update is “committed” only after a majority of voters acknowledge it, ensuring no committed state is lost on failover. Controllers periodically create snapshots to bound log size and keep an in‑memory cache for fast reads. Brokers may keep a local read‑only copy but do not participate in commits.How large should the controller quorum be, and how should it be placed?
Size the voting set to 2N+1 controllers to tolerate N failures; a majority must be available for progress. To survive a full data‑center outage, place controllers across at least three data centers so that a majority remains if one site fails.How do brokers, controllers, and clients communicate in KRaft mode?
- Admin actions from clients go to brokers, which forward metadata changes to the leader controller.- Controllers replicate metadata via leader–follower fetch and commit on majority.
- Brokers send heartbeats to the leader and periodically fetch metadata updates.
- Broker-to-broker traffic handles record replication; producers and consumers talk only to brokers.
What happens if a leader controller, follower controller, or broker fails?
- Leader controller: Followers time out, hold an election, and choose a new leader (the most up‑to‑date node). Brokers discover the new leader from the controller list and resume metadata sync.- Follower controller: It drops from quorum; the cluster continues as long as a majority remains. It resyncs and rejoins when back.
- Broker: The controller marks it failed based on missing heartbeats, reassigns partition leaders from the ISR, and updates metadata. If no ISR exists,
unclean.leader.election.enable controls whether to prefer availability (allow out‑of‑sync leader) or consistency (keep partition offline). Clients may see transient errors until metadata refreshes.How do I configure a Kafka cluster to run in KRaft mode?
- Assign roles per server withprocess.roles (controller, broker, or broker,controller) and a unique node.id across the cluster.- Define the controller quorum either statically with
controller.quorum.voters ({node_id}@{host}:{port}) or dynamically with controller.quorum.bootstrap.servers; manage membership via kafka-storage.sh and kafka-metadata-quorum.sh.- Controllers: set
listeners and controller.listener.names.- Brokers: set
controller.listener.names, controller.quorum.voters, plus network settings like listeners, advertised.listeners, and inter.broker.listener.name.How does KRaft compare to ZooKeeper-based Kafka, and why migrate?
ZooKeeper-based Kafka uses a separate ZK quorum for metadata and broker liveness, with one broker acting as the active controller. KRaft replaces ZooKeeper with an embedded controller quorum using Raft, simplifying operations, speeding metadata recovery via snapshots, and pushing metadata updates more efficiently to brokers. ZooKeeper is deprecated and slated for removal in future Kafka versions.How should I choose between on‑prem, managed cloud, and hybrid Kafka deployments?
- On‑prem: Maximum control and tuning; higher operational burden (provisioning, monitoring, security, DR). Better for large enterprises with Kafka expertise.- Managed cloud: Offloads ops and upgrades; limits deep tuning; potential higher cost and vendor lock‑in; consider data sovereignty and egress fees.
- Hybrid: Keep core systems on‑prem while feeding analytics and ML in the cloud via replication/Connect. Balance latency, compliance, and cost.
What are the realities of scaling and multi‑region Kafka?
Kafka is stateful; adding brokers doesn’t auto‑rebalance. You must move partitions, which consumes CPU, disk, and network and takes time. Scaling down requires draining brokers. Most teams capacity‑plan and over‑provision instead of relying on reactive autoscaling. Multi‑region is more feasible in cloud but introduces latency, data consistency, and networking cost considerations; controller quorums still need majority placement.How do I secure Kafka end‑to‑end: encryption, authentication, authorization, and data at rest?
- Encryption in transit: Use TLS; prefer mTLS between clients and brokers for identity and confidentiality.- Authentication: mTLS or SASL (PLAIN/SCRAM/GSSAPI/OAUTHBEARER; cloud providers may add mechanisms). Map authenticated identities to principals.
- Authorization: Define ACLs for topics, groups, cluster ops; remember consumers need group/offset and describe rights. Some providers offer RBAC.
- Data at rest: Use disk/filesystem encryption or implement end‑to‑end encryption (clients encrypt/decrypt) or a proxy that handles encryption. Manage secrets via env/files/vault and use a KMS for keys.
Kafka for Architects ebook for free