Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

How would you choose the number of partitions for a new topic carrying 20,000 events per second of order updates, consumed by three services with different processing speeds? What makes changing it later hard?

Partitions are the ceiling on consumer parallelism within a group, so we size the topic for the slowest consumer's required parallelism, measured in tests, plus headroom for growth and catch-up. We also check measured per-partition producer and consumer throughput, and we remember that partitions are not free: more open files, more replication work and longer leader elections, even though KRaft improves metadata scale. Partitions can be added but never removed, and adding them changes the key-to-partition mapping and breaks per-key ordering, so for keyed topics like order updates we over-provision at creation.

Why this question is asked

The partition count is the one topic setting that is both important and hard to change. Too few and a slow consumer can never catch up; too many and we pay in broker resources and latency. Interviewers ask it with concrete numbers to see whether we can turn throughput figures into a decision. In this answer, we will recap what partitions limit, work through the numbers for 20,000 events per second and three consumers, look at the cost of each extra partition, and see exactly why changing the count later is hard.

1What the Partition Count Limits

A partition is an ordered log stored on one leader broker and copied to followers. Each partition is consumed by exactly one member of a consumer group at a time. That gives us the most important rule: a consumer group can never process a topic with more parallel consumers than there are partitions. Each group consumes the topic independently, so our three services, with their different speeds, each need enough partitions for themselves.

Partitions also hold ordering: Kafka guarantees order only within a partition. Order updates are naturally keyed by order id, so every update for one order goes to one partition and is processed in order. That matters for the second half of the question.

2Working Through the Numbers

Suppose tests show these speeds per consumer thread: the analytics service processes 10,000 events per second, the notification service 2,000, and the fulfilment service, which writes to a database and calls another service, 400. At 20,000 events per second, analytics needs 2 consumers, notifications 10, and fulfilment 20,000 / 400 = 50. The slowest consumer decides: we need at least 50 partitions.

Then we add headroom. Traffic grows, say we plan for double within two to three years, which gives 100. Consumers also need spare capacity to catch up after an outage: if fulfilment is down for an hour, it must process the backlog while new events keep arriving. And per-partition throughput must work for producers too; with 1 KB events, 20,000 per second is 20 MB/s, or 0.2 MB/s per partition at 100 partitions, which is far below what one partition can handle. So something like 100 to 120 partitions is a defensible choice, and a number with many divisors, such as 120, spreads evenly over many consumer counts.

Required parallelism per consuming service
ServicePer-thread rate (tested)Threads needed at 20k/sWith 2x growth
Analytics10,000 events/s24
Notifications2,000 events/s1020
Fulfilment400 events/s50100
The slowest consumer sets the minimum partition count.

3Partitions Are Not Free

Each partition replica is a directory of log segment files and index files on a broker, so more partitions mean more open file handles and more small writes. Each partition's followers fetch from its leader, so replication work grows with partition count. When a broker fails, leadership of all its partitions must move, and more partitions means a longer leader election and more requests to re-route. Producers keep a batch buffer per partition, so a producer writing to many partitions spreads its records thin and batches less well, which adds latency.

Kafka 4 runs on KRaft, its built-in consensus layer, after ZooKeeper support was removed. KRaft handles metadata for many more partitions per cluster and makes failover faster, but the per-partition costs on brokers and clients remain. So we do not create 1,000 partitions just in case; we create the number our arithmetic supports.

4Why Changing It Later Is Hard

Kafka lets us add partitions to a topic but never remove them; removing would delete data. Adding is where the trap is. The default partitioner chooses a partition for a keyed record as hash(key) modulo the number of partitions. When we go from 60 to 120 partitions, most keys suddenly map to a different partition. New updates for order 7731 go to partition 85, while its older updates are still waiting in partition 25.

Now one consumer may process the new update from partition 85 before another consumer processes the old update from partition 25, so updates for the same order are applied out of order: a cancelled order may be marked shipped. Kafka does not move existing data when partitions are added, so this window lasts until the old partitions are fully drained.

Java
// default partitioner for keyed records (simplified)
int partition = Utils.toPositive(Utils.murmur2(keyBytes)) % numPartitions;
// order 7731, before and after adding partitions
// 60 partitions: partition 25 <- older updates still queued here
// 120 partitions: partition 85 <- new updates go here
// consumers of 25 and 85 run independently: per-key order is no longer guaranteed
Step throughOrder updates split across partitions after adding some
ProducerPartition 25Partition 85Consumer
order 7731: PAID (before the change)
order 7731: CANCELLED (after the change)
reads CANCELLED first
reads PAID later, from the backlog
final state PAID: wrong

5 messages in order. Play them, or step through them one at a time.

5So: Over-Provision Keyed Topics at Creation

For keyed topics where order matters, we choose a generous count at creation, based on the growth plan rather than today's load, because the cost of a few dozen extra partitions is small and the cost of re-partitioning later is large. If we do need more later, the safe path is a new topic with the new count: producers switch to it, consumers drain the old topic completely before reading the new one, and only then process the new topic. Unkeyed topics, where ordering does not matter, can simply have partitions added when needed.

6Follow-up questions

Can we get more parallelism without more partitions?

Yes, within limits. A consumer can process records from its partitions with several worker threads, as long as records of the same key are processed in order, for example by hashing keys to worker threads. Libraries such as Confluent's parallel consumer do this. It adds complexity around offset commits, so more partitions remain the simpler first choice.

Is there an upper limit on partitions per cluster?

There are practical limits that depend on hardware, Kafka version and replication factor. KRaft clusters support far more partitions than ZooKeeper-based ones did. Check your version and vendor guidance, and test failover times with your real partition count.

7Conclusion

In this answer, we chose a partition count for 20,000 order updates per second by sizing for the slowest consumer's parallelism, measured per thread, plus growth and catch-up headroom, which led to about 100 to 120 partitions. We weighed the costs of partitions in files, replication and leader elections, which KRaft eases but does not remove. And we saw that partitions cannot be removed and adding them changes key-to-partition mapping, breaking per-key ordering, so keyed topics are over-provisioned at creation.

What to say in the interviewAbout 100 seconds aloud

Open with

I start from the rule that each partition is consumed by one member of a group, so the partition count caps each service's parallelism. Each of the three services consumes independently, so the slowest one decides.

Then, if they want more

I would measure per-thread throughput in tests; say fulfilment handles 400 events per second per thread, notifications 2,000 and analytics 10,000. At 20,000 events per second, fulfilment needs 50 consumers, so 50 partitions is the minimum.

Then I add headroom: maybe double for growth over a few years, plus spare capacity to catch up after an outage, which takes me to about 100 or 120, and I would pick a number like 120 that divides evenly.

I would also check producer throughput per partition, but at 1 KB per event that is only about 20 MB per second in total, so it is not the constraint.

I would not go much higher, because partitions cost open files, replication fetches, longer leader elections and less efficient producer batching; KRaft in Kafka 4 helps with metadata scale, but those costs remain.

The reason to get it right up front is that partitions can be added but not removed, and adding them changes hash of key modulo partition count, so updates for the same order land on different partitions and can be processed out of order.

For a keyed topic like order updates I over-provision at creation, and if I ever need more, I create a new topic and drain the old one first.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How would you choose the number of partitions for a new topic carrying 20,000 events per...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/a7c764d678/