Apache Kafka Kafka Admin & Operations 2 — Questions and Answers
Question 1: How do you reset a consumer group's offsets to the earliest available message using the CLI?
- kafka-consumer-groups.sh --reset-offsets --to-earliest --execute (Correct answer)
- kafka-console-consumer.sh --from-beginning --reset
- kafka-offsets.sh --reset --start-earliest
- kafka-topics.sh --reset-offsets --to-earliest
Correct answer: kafka-consumer-groups.sh --reset-offsets --to-earliest --execute
kafka-consumer-groups.sh with --reset-offsets --to-earliest --execute resets all offsets for a consumer group to the beginning of each partition.
Question 2: What is the primary role of the Kafka Controller broker in a cluster?
- It routes all producer requests to the correct partition leader
- It manages ZooKeeper connections on behalf of all brokers
- It handles partition leader election and broker failure recovery (Correct answer)
- It compresses and deduplicates messages before storage
Correct answer: It handles partition leader election and broker failure recovery
The Kafka Controller is an elected broker responsible for managing partition leader elections, tracking broker liveness, and coordinating cluster state changes.
Question 3: What is a 'preferred replica' in Kafka?
- The replica with the most up-to-date data at any given time
- The first replica in the assigned replica list, which is the ideal partition leader (Correct answer)
- The replica residing on the broker with the least network load
- The replica that was most recently added to the ISR
Correct answer: The first replica in the assigned replica list, which is the ideal partition leader
The preferred replica is the first entry in the partition's assigned replica list; Kafka tries to keep this replica as the leader for balanced load distribution.
Question 4: What information does `kafka-log-dirs.sh` provide?
- Disk usage and replica lag information per broker and partition (Correct answer)
- A listing of all Kafka log segment filenames
- Compression ratio statistics for stored messages
- The schedule for upcoming log segment rotation
Correct answer: Disk usage and replica lag information per broker and partition
kafka-log-dirs.sh reports disk usage per log directory and per partition, along with replica offset lag, helping identify storage hotspots.
Question 5: Which JMX metric reports the number of under-replicated partitions in a Kafka cluster?
- kafka.server:type=ReplicaManager,name=LeaderCount
- kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions (Correct answer)
- kafka.controller:type=KafkaController,name=ActiveControllerCount
- kafka.network:type=RequestMetrics,name=TotalTimeMs
Correct answer: kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions
kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions counts partitions with fewer in-sync replicas than the configured replication factor, a key health indicator.
Question 6: What does the `auto.create.topics.enable` broker configuration setting control?
- Whether Kafka automatically rebalances partitions across new brokers
- Whether Kafka automatically creates a topic when it is first referenced by a producer or consumer (Correct answer)
- Whether Kafka automatically adjusts the replication factor for under-replicated topics
- Whether consumers can create private topics for internal use
Correct answer: Whether Kafka automatically creates a topic when it is first referenced by a producer or consumer
When auto.create.topics.enable=true, Kafka creates a topic automatically the first time it is referenced, using default partition and replication settings.
Question 7: Which configuration setting controls how often Kafka flushes data from OS page cache to disk?
- log.flush.interval.ms (Correct answer)
- log.segment.bytes
- log.roll.hours
- log.index.interval.bytes
Correct answer: log.flush.interval.ms
log.flush.interval.ms determines how frequently Kafka forces an fsync to flush buffered data from the OS page cache to durable disk storage.
How do you reset a consumer group's offsets to the earliest available message using the CLI?