Kafka Controller and Leadership
Broker Roles
Brokers can serve three distinct roles:
- Leader
- Group Coordinator
- Controller
Controller Responsibilities
-
Partition Management
- Leader election for partitions
- Monitoring broker failures
- Maintaining cluster metadata
-
Split-Brain Prevention
- Uses controller epoch numbers
- Higher numbers for new controllers
- Ignores messages from old epochs
-
ZooKeeper Integration
- Controller election via ZooKeeper
- Only one active controller at a time
- Automatic failover on controller failure
Leadership Changes
-
Planned Changes
- Rolling restarts
- Broker maintenance
- Configuration updates
-
Unplanned Changes
- Broker failures
- Network partitions
- ZooKeeper connection loss
References
Flashcards
What are the three possible roles a broker can have?:: Leader, Group Coordinator, and Controller
How does Kafka prevent split-brain with controllers?:: Uses controller epoch numbers - higher numbers for new controllers and ignores old epoch messages
What happens when a broker loses ZooKeeper connection?:: Its ephemeral node is removed but broker ID remains in other data structures