A new topic must carry 30,000 messages a second. One consumer finishes 1,500 a second, and one partition can take 10,000 a second from producers. How many partitions do you create?
Sketch your own answer first, then compare it with the one below.
A strong answer
Take the larger of the two requirements. Producers need 30,000 / 10,000 = 3 partitions. Consumers need 30,000 / 1,500 = 20. So 20 is the floor, set by the consumer side.
I would not stop at 20. If traffic is likely to double, 40 leaves room to add consumers without touching the topic, which matters because changing the count later remaps keys. Running 20 consumers on 40 partitions means two partitions each, which is fine.
Going far past that has costs. More partitions mean more open files, longer leader elections when a broker fails, bigger rebalances and smaller producer batches. Sizing for twice the projected need is a reasonable balance.
Check the assumption behind the number too. The formula assumes load spreads evenly over keys. If one key carries a large share, the partition holding it needs a consumer faster than 1,500 a second, and no partition count fixes that.
Sources
- Jun Rao (2015). How to choose the number of topics/partitions in a Kafka cluster?.
- Jay Kreps, Neha Narkhede, Jun Rao (2011). Kafka: a distributed messaging system for log processing.