What are the considerations for choosing the number of partitions in a Kafka topic?
Instruction: Explain the factors that should be considered when deciding on the number of partitions for a Kafka topic.
Updated
Official answer
Choose partition count from measured throughput, ordering requirements and operational capacity. For standard partition-assigned consumer groups, each partition has one owning consumer at a time, so extra group members beyond the partition count are idle. This statement is about ordinary consumer groups, not Kafka's separate share-group model.
Measure sustainable producer and consumer throughput per partition on representative hardware, payloads and processing logic. A rough lower bound is the larger of total ingress divided by measured write capacity per partition and total processing demand divided by measured consume capacity per partition, rounded up. Then add justified growth/failure headroom and validate skew. A hot key can remain a bottleneck regardless of the total count.
More partitions increase replica, metadata, file, memory, recovery and coordination costs. Budget these across brokers and the KRaft controllers, together with replication factor and retention. More partitions are not themselves a durability policy.
Keys define an ordering domain only while routing remains consistent. Increasing a topic's partition count can change key-to-partition mapping, so old and new records for one key may occupy different partitions. Kafka does not simply shrink an existing topic's partition count; a migration can require a new topic and controlled cutover.
Test peak load, one-broker loss, rebalance and restoration. Prefer a measured plan over a universal partitions-per-broker number.