What are the implications of changing a Kafka topic's partition count?
Instruction: Discuss the effects and considerations of modifying the partition count for an existing Kafka topic.
Updated
Official answer
Increasing a topic's partition count can increase parallelism for a conventional consumer group, up to the number of independently processable partitions. It also adds logs, replicas, metadata and operational overhead. It is not an automatic throughput improvement.
The critical ordering issue is key routing. If a producer uses a mapping such as hash(key) % partition_count, increasing the count can send future records for an existing key to a different partition. Existing records remain in their original partitions; Kafka does not redistribute that history. Two consumers can then process old and new records for the same key concurrently, breaking the application's intended per-key sequence.
Review the actual partitioner, explicit partition choices and producer update timing. For workflows requiring strict continuity, use a planned migration/drain barrier, an application ordering/version protocol or a suitably designed stable routing scheme. Do not assume that preserving the key bytes preserves ordering after the partition count changes.
Consumers may rebalance to acquire new partitions. Stateful applications, co-partitioned joins, external partition mappings and monitoring also need a compatibility check. More consumers cannot fix a single hot key that still must be processed serially.
Kafka does not support decreasing an existing topic's partition count directly. A smaller topic requires a migration with explicit offsets/state and cutover behavior. Measure per-partition bytes/rates, hot spots, end-to-end age and failure recovery before and after any change. Treat the change as a data-routing decision as well as a capacity decision.