Size from target throughput and consumer parallelism, add growth headroom, and respect ordering and operational limits
I treat it as a sizing calculation with guardrails, because the count is hard to change later. First, estimate peak target throughput T for the topic. Measure, do not guess, the throughput one partition can sustain for producers (Pp) and for a consumer doing the real processing (Pc). The minimum is max(T/Pp, T/Pc). Example: T = 200 MB/s, Pp = 20 MB/s, Pc = 10 MB/s gives max(10, 20) = 20. Then I add headroom for growth, typically 1.5x to 3x, and round to a number with many divisors (for example 48) so consumers can be spread evenly. The consumer side usually dominates, because processing is slower than appending.
Consumer parallelism: the count caps useful consumers in a group, so I size for the maximum consumer count I expect to run, not today's count.
Ordering: if per-key order matters, the key space defines what is possible. Increasing partitions later changes key mapping, which is why I over-provision up front for keyed topics rather than expand later.
Operational cost: each partition adds file handles, replication load, producer batch memory, controller work and rebalance time. Too many partitions hurt end-to-end latency and recovery time.
Retention and storage: per-partition size matters for recovery and rebalancing; very large partitions take long to move.
Trade-off: over-provisioning wastes resources but is cheap to run; under-provisioning forces a painful repartition. I lean towards modest over-provisioning for important keyed topics, and towards starting small for stateless, unkeyed ones where growing is harmless.
Common mistake: copying a number from a blog post (100 everywhere) or from the consumer count of today. Another is expecting to fix a hot key by adding partitions, which it will not do.
Version note: older ZooKeeper-based guidance on partitions per broker is conservative for KRaft, and Kafka 4.0 is KRaft only. Validate limits with a load test on your version and hardware.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience