ScenarioProduction Scenarios
How do you safely increase the partition count of an existing Kafka topic?
Reference answer
Important caveat: adding partitions does not change the partitioning of existing data, and with hash(key) % number_of_partitions the key mapping will potentially be shuffled, so the same key may now land in a different partition and consumers that rely on a key's partition may be disturbed. Steps: 1) Check whether any consumer or downstream logic depends on key-to-partition ordering or locality, and plan for a period in which a key's older records sit in one partition and newer ones may be in another. 2) Run kafka-topics.sh --alter --topic NAME --partitions N; you can only increase the count, because Kafka does not support reducing the number of partitions. 3) Existing records stay in their old partitions: Kafka does not redistribute data automatically, while new records spread across all partitions. 4) Consumer group assignments will change as the new partitions are picked up, so expect some disruption. 5) If you need to keep key affinity, create a new topic with more partitions, move producers to it, then migrate consumers once the old topic is drained. 6) Rehearse in staging first.
Expected key concepts: hash(key), existing data, kafka-topics.sh --alter, only increase, key affinity, new topic, migrate, consumer group, assignments, staging
How did that feel?
Your own verdict, not the score. It shows up next to this question in the list, so you can come back to the shaky ones.