How Many Kafka Partitions? Count, Consumers & Sizing

Take the larger of 2 numbers: the partitions your producers need, and the partitions your consumers need to hit the target throughput. Then round up to a count your consumer group sizes divide evenly. The partition count is also the most consumers a group can use, so extra consumers sit idle, and you can raise it later but never lower it.

Last updated: Proudly published by: Jeff Wahl7 min read

How many partitions should a Kafka topic have?

Pick the larger of 2 numbers: the partitions your producers need to reach the target throughput, and the partitions your consumers need to keep up with it. Round up to a count your planned consumer group sizes divide evenly, and leave room for growth, because the count can be raised later but never lowered. A topic created with no count gets 1 partition from the broker default num.partitions.

A partition is the unit of parallelism in Kafka. It's an ordered log that lives on 1 broker as leader, and it's read by at most 1 consumer of a consumer group at a time. So the partition count caps how many consumers a group can use, sets how write and read load spread across brokers, and defines the scope of ordering, since order holds only inside 1 partition.

Prepare for the interview
01 / Open invite
02min.

Know Kafka partition count the way the interviewer who asks it knows it.

a Kafka partition count query, the same shape a screen would give you.
The diff against expected. Where ties broke. What you missed.
sandbox
1source → bronze → silver → gold
2 ingest : CDC + Kafka
3 transform : dbt + Airflow
4 serve : Snowflake
5
Execute your solution0.4s avg.

Partitions vs consumers: why extra consumers sit idle

The Apache Kafka design documentation says each partition is consumed by exactly 1 consumer within each subscribing consumer group at any given time. A group of 3 consumers on a topic with 6 partitions gives each consumer 2. Add consumers and the load spreads thinner, up to 1 partition each.

Past that point more consumers add nothing. A group of 8 consumers on 6 partitions has 2 consumers with no partition: they join the group but hold no assignment, standing by to take over if a busy consumer fails. The partition count is therefore the ceiling on a group's useful size: a group can have fewer consumers than partitions, never more doing work.

Topic with 6 partitions read by a group of 3 consumers, each holding 2 partitions, and by a group of 8 consumers, where 6 hold 1 partition each and 2 are idleTopic with 6 partitions read by a group of 3 consumers, each holding 2 partitions, and by a group of 8 consumers, where 6 hold 1 partition each and 2 are idle

Separate consumer groups don't compete. Each group reads every partition on its own, so a second application reading the same topic adds no constraint on the first, and each group's ceiling is the same partition count.

How to size the partition count from throughput

Formula
partitions = max( ceil(target / producer rate), ceil(target / consumer rate) )
target
Peak throughput the topic must carry, in MB/s
producer rate
MB/s 1 partition sustains on the write side, measured with your batch size and compression
consumer rate
MB/s 1 consumer sustains on 1 partition, including your processing and any sink it writes to
A 120 MB/s topic
Producer side12partitions
Consumer side24partitions
Needed24partitions

Where the per-partition rates come from

The 2 rates are measurements, not constants, and the example values (10 MB/s and 5 MB/s) are assumptions to replace with your own. Measure the producer rate against a topic with 1 partition, using your real record size and your batching and compression settings. Measure the consumer rate with the real processing code, because the slowest step usually sits after the read: a database write or an API call, not Kafka.

In the example the consumer side decides: 12 partitions would carry the writes, but consumers at 5 MB/s per partition need 24. When the consumer side is the larger number, the cheaper fix is often a faster consumer, since halving the processing cost per record halves the partitions needed. Take the count from the faster consumer only if you've measured that it exists.

Plan for the peak you expect over the life of the topic, not today's average. Since the count can be raised later at a cost to key ordering, a modest margin of 1.5x to 2x on the computed number is a reasonable place to start, and a number that is several times larger buys nothing but overhead.

Choose a count your consumer group sizes divide evenly

Partitions are handed out whole, so a count that does not divide by the group size leaves some consumers with more. With 24 partitions, a group of 6 consumers gives each 4 partitions and a group of 8 gives each 3. A group of 10 gives some consumers 3 and others 2, so its busiest consumer carries the same 3 as a group of 8 and the 2 extra consumers buy no relief.

The busiest consumer sets the group's pace, because it falls behind first. A count with many divisors, such as 24, lets the group grow through 2, 3, 4, 6, 8 and 12 consumers with an even split each time. A prime count like 13 or 23 splits evenly only at 1 consumer or at 1 per partition. Idle consumers appear when a group is larger than the count: 4 idle at 28 consumers on 24 partitions.

Partition count, keys and ordering

Kafka guarantees that a consumer reads a topic-partition's events in the order they were written, and that events with the same key go to the same partition. That gives per-key ordering, for example every event for 1 customer in sequence, and none across keys. If a topic needs 1 global order, it needs 1 partition and at most 1 active consumer per group, which caps its throughput at what 1 partition carries.

The key-to-partition mapping depends on the count. The Apache Kafka operations documentation warns that with the default partitioner, which uses a hash of the key modulo the number of partitions, raising the count changes the mapping, so messages with the same key may route to different partitions after the expansion and per-key ordering can break for existing keys. Kafka doesn't redistribute existing data.

The same page states that Kafka does not currently support reducing the number of partitions for a topic. Together these make the count a one-way decision for any topic whose consumers depend on key order or keep per-key state: pick it with growth in mind, or plan a new topic and a migration. A topic whose consumers keep no per-key state can grow with little trouble.

Create a topic and add partitions

# create a topic with 24 partitions
bin/kafka-topics.sh --bootstrap-server localhost:9092 \
  --create --topic orders --partitions 24 --replication-factor 3

# see the partition count and each partition's leader
bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders

# raise the count (it can never be lowered)
bin/kafka-topics.sh --bootstrap-server localhost:9092 \
  --alter --topic orders --partitions 48

Raising the count changes where a key hashes to, so existing keys can move partitions

What too many partitions costs

A producer keeps a batch per partition it writes to, sized by batch.size (16,384 bytes by default), all drawn from buffer.memory (33,554,432 bytes by default), enough for 2,048 full batches. A consumer can fetch up to max.partition.fetch.bytes per assigned partition, 1 MiB by default, so its memory use grows with the partitions it owns. Brokers keep files and replicas for each partition.

Spreading the same traffic over more partitions also makes each batch smaller, since a producer fills 1 batch per partition and sends it when it's full or when linger.ms expires. Smaller batches mean more requests for the same bytes. A topic with far more partitions than the throughput needs pays these costs for nothing, so choose the smallest count that meets the sizing and consumer targets with some margin.

The Kafka settings that interact with partition count

num.partitions
1 partition for a topic created without a count
batch.size
16,384 bytes per partition batch
buffer.memory
33,554,432 bytes across all partition batches
max.partition.fetch.bytes
1,048,576 bytes per partition per fetch
Defaults from the Apache Kafka 4.1 configuration reference

How partition count comes up in data engineering interviews

Interviewers ask this as a design question: pick a partition count for an event stream and defend it. A strong answer gives the throughput arithmetic from both sides, names the key that preserves order, states the consumer group ceiling and says how to change the count later and what that breaks. It works as a short calculation to practice, so run the sizing formula with your own numbers.

Kafka questions show up across the Kafka interview questions set and in design rounds. The data pipeline interview questions and data pipeline practice problems cover the streaming pipelines these partitions feed, and the data engineer interview prep guide maps the rest of the loop. For the basics of topics, producers and brokers, see the Kafka tutorial.

Kafka partitions FAQ

How many partitions should a Kafka topic have?+
Enough for the larger of 2 numbers: the target throughput divided by what 1 partition sustains on the producer side, and the same target divided by what 1 partition sustains on the consumer side. With a 120 MB/s target, 10 MB/s per partition for producers and 5 MB/s for consumers, that is 24. Then round up to a count your planned consumer counts divide evenly.
What is the default number of partitions?+
The broker setting num.partitions defaults to 1, so a topic created without a partition count has 1 partition and at most 1 active consumer per group.
What happens when there are more consumers than partitions?+
In a consumer group each partition is read by exactly 1 consumer at a time, so the extra consumers hold no partitions and do no work. A group of 8 consumers on a topic with 6 partitions leaves 2 idle.
Can I increase the number of partitions of an existing topic?+
Yes, with the alter action of the kafka-topics tool. Existing records stay where they are, and with the default partitioner the hash of a key maps to a different partition once the count changes, so the same key can land on a new partition and break per-key ordering across the change.
Can I reduce the number of partitions?+
No. The Apache Kafka documentation states that Kafka doesn't currently support reducing the number of partitions for a topic. The usual route is a new topic with the right count and a migration of producers and consumers.
Is more partitions always better?+
No. Each partition adds a producer batch buffer, a per-partition fetch allowance on every consumer reading it and more files for the brokers to manage. Pick the smallest count that meets the throughput and consumer parallelism you need, with room to grow.
Do partitions guarantee ordering?+
Only within 1 partition. Kafka guarantees that a consumer reads the events of a topic-partition in the order they were written, and events with the same key go to the same partition. Across partitions there is no order.
02 / Why practice

The candidate who gets the offer

  1. 01

    Reading a solution is not the same as writing one

    Every engineer who has frozen on a query they had read a dozen times knows the gap. The only preparation that closes it is producing the answer yourself, under time, before the interview does it for you

  2. 02

    76% of hiring managers reject on the coding task, not the resume

    From HackerRank's 2024 Developer Skills Report. Candidates who look strong on paper still fail the live screen if they haven't done timed, executable practice

  3. 03

    System design comes down to the calls you defend out loud

    Ingestion, batch vs streaming, the bronze/silver/gold layers, idempotency, backfill and replay. Sketching the pipeline and naming the failure modes is the signal, not the boxes

Related guides