Apache Kafka Kafka Topics & Partitions 1 — Questions and Answers
Question 1: What is the purpose of the replication factor in a Kafka topic?
- It defines how many copies of each partition exist across brokers for fault tolerance (Correct answer)
- It controls the number of partitions
- It sets the maximum message size
- It determines compression type
Correct answer: It defines how many copies of each partition exist across brokers for fault tolerance
The replication factor specifies how many broker copies exist for each partition, ensuring data durability if a broker fails.
Question 2: Which Kafka CLI tool is used to create a new topic?
- kafka-topics.sh (Correct answer)
- kafka-console-producer.sh
- kafka-configs.sh
- kafka-log-dirs.sh
Correct answer: kafka-topics.sh
kafka-topics.sh with the --create flag is the standard tool for creating new Kafka topics from the command line.
Question 3: What determines which partition a keyed message is written to?
- hash(key) % number_of_partitions (Correct answer)
- Round-robin based on timestamp
- Producer ID modulo partition count
- Key length modulo partition count
Correct answer: hash(key) % number_of_partitions
By default, Kafka uses the murmur2 hash of the key modulo the number of partitions to determine the target partition for a keyed message.
Question 4: What is the minimum in-sync replicas (min.insync.replicas) setting used for?
- Defines the minimum number of replicas that must acknowledge a write when acks=all (Correct answer)
- Sets the minimum partition count
- Controls leader election timeout
- Limits the replication factor
Correct answer: Defines the minimum number of replicas that must acknowledge a write when acks=all
min.insync.replicas specifies how many replicas must be in-sync for a produce request with acks=all to succeed, preventing data loss.
Question 5: Can you decrease the number of partitions in an existing Kafka topic?
- No, partition count can only be increased, never decreased (Correct answer)
- Yes, using kafka-topics.sh --alter
- Yes, but only if replication factor is 1
- Yes, by temporarily disabling the topic
Correct answer: No, partition count can only be increased, never decreased
Kafka does not support decreasing the partition count of an existing topic because it would require redistributing data and break ordering guarantees.
Question 6: What is a Kafka topic's 'retention.ms' configuration?
- The time period for which Kafka retains messages before deleting them (Correct answer)
- Maximum size before a segment is closed
- Time to wait before a compacted key is removed
- Consumer group session window
Correct answer: The time period for which Kafka retains messages before deleting them
retention.ms controls how long Kafka keeps messages in a topic before they are eligible for deletion based on age.
What is the purpose of the replication factor in a Kafka topic?