Apache Kafka Kafka Topics & Partitions 2 — Questions and Answers
Question 1: What is a Kafka 'leader' partition?
- The single replica that handles all reads and writes for a partition (Correct answer)
- The oldest replica across brokers
- The replica with the highest offset
- The broker that manages ZooKeeper metadata
Correct answer: The single replica that handles all reads and writes for a partition
Each partition has exactly one leader replica that handles all producer writes and (by default) consumer reads; followers replicate from it.
Question 2: What does 'log compaction' do in a Kafka topic?
- Retains only the latest message for each key, removing older duplicates (Correct answer)
- Compresses log segments using gzip
- Merges multiple segments into one
- Removes all messages older than retention.ms
Correct answer: Retains only the latest message for each key, removing older duplicates
Log compaction ensures that for each key, only the most recent message value is retained, acting like an upsert store for change-data-capture use cases.
Question 3: What is the purpose of the `__consumer_offsets` internal topic in Kafka?
- Stores committed consumer group offsets so consumers can resume after restart (Correct answer)
- Logs producer errors
- Tracks broker health metrics
- Stores admin ACL configurations
Correct answer: Stores committed consumer group offsets so consumers can resume after restart
__consumer_offsets is an internal Kafka topic that durably stores the committed offsets for all consumer groups.
Question 4: What is an ISR (In-Sync Replica) set?
- The set of replicas that are fully caught up with the leader's log (Correct answer)
- All replicas regardless of replication lag
- Only the leader replica
- Replicas assigned to the controller broker
Correct answer: The set of replicas that are fully caught up with the leader's log
The ISR is the subset of a partition's replicas that have replicated all messages up to a configurable threshold and are considered 'caught up' with the leader.
Question 5: What command lists all topics in a Kafka cluster?
- kafka-topics.sh --bootstrap-server <host> --list (Correct answer)
- kafka-topics.sh --zookeeper <host> --describe
- kafka-configs.sh --list-topics
- kafka-admin.sh --list
Correct answer: kafka-topics.sh --bootstrap-server <host> --list
kafka-topics.sh --list with --bootstrap-server connects to the cluster and lists all existing topic names.
Question 6: What is the impact of increasing the number of partitions on a topic that already has consumers?
- It triggers a consumer group rebalance as partitions are redistributed (Correct answer)
- Consumers are automatically updated with no interruption
- It only affects new consumer groups
- Partition increase requires topic deletion and recreation
Correct answer: It triggers a consumer group rebalance as partitions are redistributed
Adding partitions to a topic causes the group coordinator to initiate a rebalance so that the new partitions are assigned to consumer group members.
What is a Kafka 'leader' partition?