03 / 05

How would you choose the number of partitions for a new production topic?

Difficulty: 5/10
Partitioning and ordering

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.

  1. 1

    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.

  2. 2

    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.

  3. 3

    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.

  4. 4

    Retention and storage: per-partition size matters for recovery and rebalancing; very large partitions take long to move.

  5. 5

    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.

  6. 6

    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.

  7. 7

    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.

javascript
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.