liveBook · Manning

Controller

As explained in Apache Kafka in Action

A Kafka controller is a broker designated to manage partition and replica state, including partition assignments and leader selection.

When a Kafka cluster has several brokers, they need a consistent answer to two questions: which brokers hold each partition, and which replica is its leader? The controller manages those assignments and changes them when a broker fails. This keeps partitions available without leaving each broker to make conflicting decisions. section 4.3.1 section 7.0

In a KRaft cluster, brokers can be configured for controller or broker roles. Controller-role nodes form a coordination cluster that elects one active controller; the others stand by. If the active controller fails, a standby can take over. One controller-broker is enough for local development but offers no controller failover. Three can tolerate one controller-broker failure; five can tolerate two. section 7.1

When a partition leader fails

Suppose a client is fetching messages when the broker leading its partition becomes unavailable. The controller detects the failure and triggers an election that promotes a replica. The client may briefly fail to fetch; it then requests updated metadata and connects to the new leader. Clients subsequently communicate with the responsible broker, not through the controller. section 7.4

The controller depends on cluster coordination, not a manually fixed leader. Older Kafka deployments used ZooKeeper to elect the controller and store metadata. KRaft integrates coordination into Kafka and uses the __cluster_metadata topic for cluster metadata, avoiding a separate ZooKeeper system. When planning a deployment, distinguish controller-role nodes from the single controller currently active. section 4.3.1 section 7.1

How Apache Kafka in Action covers it

How deep it goes
Explains active and standby controllers, failure takeover and deployment counts, but does not detail the election protocol.
Examples
Traces a failed partition leader through controller-triggered election, client metadata refresh and reconnection.
What it assumes
Builds from single-broker intuition toward multi-broker coordination while relying on the concepts of brokers, partitions and replicas.
What you can do after
Operate/configure it by choosing one controller-broker for local development or three or five for failure tolerance.
How it connects
Connects controllers to brokers, partitions, replicas, leader election, cluster metadata, KRaft and ZooKeeper.

Also explained in

Compare how 2 books explain controller →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.