Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Deep Dive into KRaft Consensus: Leader Elections and Metadata Quorum.
senior LevelSystem DesignApache Kafka
In Simple Words: In KRaft, metadata is managed by a small quorum of controller nodes (typically 3 or 5 controllers) running a specialized Raft consensus state machine:
- Unlike ZooKeeper, which required periodic snapshot syncs and full metadata tree watches, KRaft controllers write metadata records directly to an internal, replicated
@metadatatopic. - Active Controller: One node is elected leader. When a metadata change occurs (e.g. topic created, partition reassigned), the active controller appends the record to
@metadataand replicates it to follower controllers via Raft. - Brokers maintain an in-memory replica of this metadata log by fetching from the active controller, enabling sub-second reaction to broker failures.