Partition Count Planning in Apache Kafka

Partition Count Planning in Apache Kafka

How to decide how many partitions a Kafka topic should have, why the number matters for speed, ordering, cost and stability, and how to plan it so you do not regret it six months later.

Imagine you are opening a new supermarket. Before the doors open, you must decide how many checkout counters to build. Build too few and customers wait in long lines on busy Saturdays. Build too many and you pay for counters, cashiers and electricity that sit idle most of the week. Worse, once the shop is built, knocking down walls to add counters is expensive and disruptive. Kafka partitions are the checkout counters of your data pipeline, and deciding how many to create is called partition count planning.

This tutorial walks through the topic slowly, starting from what a partition is and ending with a repeatable planning method, common traps, and real-world patterns. You do not need to know Kafka internals beforehand. Every new term is explained the first time it appears, with an everyday comparison to make it stick.

1Start Here: What Is a Kafka Partition?

Before we plan the number of partitions, we need a clear picture of what one partition actually is.

Kafka in one paragraph

Apache Kafka is a system for moving and storing streams of events. An event is a small record of something that happened, such as a customer placing an order, a sensor reporting a temperature, or a user clicking a button. Programs that write events are called producers. Programs that read events are called consumers. The machines that store the events and serve them are called brokers, and a group of brokers working together is a cluster.

Topics and partitions

Events in Kafka are organised into named streams called topics. A topic called “orders” holds all order events. But a topic is only a label. The real storage happens in partitions. A partition is an ordered, append-only log of events. New events are always added to the end, and each one receives a sequential position number called an offset. Once written, an event is never changed in place.

A topic is split into one or more partitions, and those partitions are spread across the brokers in the cluster. When a producer sends an event, Kafka picks exactly one partition for it. When a consumer reads, it reads from partitions. So the partition is the smallest unit that Kafka can place on a broker, copy to another broker, and hand to a consumer.

Simple Analogy

Think of a topic as a highway and partitions as its lanes. Cars are events. One lane keeps cars in strict order, one behind the other. More lanes let more cars travel at the same time, but cars in different lanes have no guaranteed order relative to each other. The number of lanes is decided when the road is built.

flowchart LR
  P1["Producer A"] --> T
  P2["Producer B"] --> T
  subgraph T["Topic: orders"]
    direction TB
    PA["Partition 0"]
    PB["Partition 1"]
    PC["Partition 2"]
    PD["Partition 3"]
  end
  PA --> B1["Broker 1"]
  PB --> B2["Broker 2"]
  PC --> B3["Broker 3"]
  PD --> B1
        
FIG 1 — A topic is split into partitions, and partitions are spread across brokers

Key terms at a glance

Term 1

Partition

An ordered log that stores a slice of a topic. The basic unit of storage, copying and parallel work.

Term 2

Offset

The position number of an event inside one partition. Offsets are only meaningful within a single partition.

Term 3

Replica

A copy of a partition kept on another broker for safety. Each partition normally has several replicas.

Term 4

Leader

The one replica of a partition that handles all reads and writes. The others follow it.

Term 5

Consumer Group

A team of consumers sharing the work of reading a topic, with each partition read by only one team member at a time.

Term 6

Message Key

An optional label on an event, such as a customer ID, used to decide which partition the event lands in.

2What Is Partition Count Planning?

It is the practice of choosing how many partitions a topic should have, on purpose, using numbers instead of guesses.

Partition count planning means estimating how much data a topic must handle today and in the future, how many consumers will need to read it in parallel, what ordering rules the business needs, and how much load the brokers can safely carry. From those inputs you choose a partition count that is large enough to avoid bottlenecks and small enough to avoid waste and instability.

Why not just pick a big number?

A common beginner reaction is to say “more is always better, so let us create a thousand partitions for every topic.” Partitions are not free. Each one consumes file handles, memory, network traffic for replication, and work for the cluster controller. Too many partitions make broker restarts slower, make leader elections longer, and make clients use more memory. The goal is a balanced number, not a huge one.

Why not just pick a small number?

The opposite mistake is choosing one or two partitions because it feels simple. A topic with a single partition can only be read by one consumer at a time within a group, and it can only live on one broker for writes. When traffic grows, there is no way to spread the load without changing the design.

Simple Analogy

Planning partitions is like planning the number of classrooms in a school. One giant classroom with a single teacher cannot serve a thousand students. A thousand tiny classrooms means a thousand teachers, a thousand rooms to heat and clean, and chaos when the principal needs to gather everyone. A sensible number of classrooms, sized to the students you expect, keeps learning smooth.

“The partition count is a promise about the future, made with information from the present.”
1 topic
many partitions
1 partition
at most one active consumer per group
Up only
partition count can grow but never shrink
i
Remember

Partition count is set per topic, not per cluster. Different topics in the same cluster can and should have different counts based on their own traffic and needs.

3Partitions Are the Unit of Parallelism

Almost every reason to plan partition count comes back to one idea: partitions decide how much work can happen at the same time.

Parallelism on the producer side

Producers send batches of events to the leader of each partition. When a topic has more partitions, its leaders are spread over more brokers, so writes are shared across more disks and network cards. A single partition leader can only accept writes as fast as one broker can handle for that partition, so a topic that must absorb very high write rates needs enough partitions to spread the load.

Parallelism on the consumer side

On the reading side, the rule is strict. Inside one consumer group, each partition is assigned to at most one consumer at any moment. This guarantees that events in a partition are processed in order by a single worker. The consequence is important: if a topic has six partitions, a group can have at most six consumers doing useful work. A seventh consumer would simply wait, idle, as a spare.

flowchart TB
  subgraph Topic["Topic with 4 partitions"]
    P0["P0"]
    P1["P1"]
    P2["P2"]
    P3["P3"]
  end
  subgraph Group["Consumer group with 3 consumers"]
    C1["Consumer 1"]
    C2["Consumer 2"]
    C3["Consumer 3"]
  end
  P0 --> C1
  P1 --> C1
  P2 --> C2
  P3 --> C3
        
FIG 2 — Each partition goes to one consumer in the group, but one consumer may hold several partitions
Simple Analogy

Picture a pizza restaurant with four ovens and a team of cooks. Each oven can only be tended by one cook at a time, so hiring a fifth cook does not speed up baking because there is no free oven. If you expect to need ten cooks during a festival, you must install ten ovens beforehand.

!
Common Misconception

Adding more consumers than partitions does not increase throughput. The extra consumers stay idle. To scale reading beyond the current partition count, you must add partitions first.

Independent groups do not compete

Different consumer groups read the same topic independently. A billing service group and an analytics group can each read every event, and each keeps its own progress. The partition-to-consumer rule applies inside each group separately, so the number of partitions limits the parallelism of your largest group, not the number of groups.

4Keys, Ordering and the Hash Trap

Ordering is where partition planning turns from a math problem into a design decision.

What Kafka guarantees about order

Kafka guarantees order only inside a single partition. If event A is written before event B into the same partition, every consumer will see A before B. Across different partitions, there is no ordering guarantee at all. Two events in different partitions may be read in any relative order.

How keys choose partitions

When a producer attaches a key to an event, the default behaviour is to run the key through a hash function and use the result to choose a partition, roughly the hash value divided by the partition count, keeping the remainder. The important consequence is that the same key always goes to the same partition, as long as the partition count stays the same. This is how you keep all events for one customer, one order or one device together and in order.

flowchart LR
  E["Event with key: customer-42"] --> H["Hash the key"]
  H --> M["Take remainder by partition count"]
  M --> P["Always the same partition"]
        
FIG 3 — The key is hashed and mapped onto a partition, so equal keys stay together
Simple Analogy

A post office sorts letters by postal code into mailbags. All letters for one postal code always go to the same bag. If the post office suddenly changes how many bags it uses, the same postal code may now land in a different bag, and letters that were meant to travel together get split up.

The hash trap

This is the single most important planning warning in the whole topic. If you increase the partition count of a keyed topic later, the mapping changes. A key that used to land in partition 2 may now land in partition 5. New events for that key go to the new partition while old events remain in the old one. During the transition, consumers may see events for one key out of order, and stateful programs that assumed one key lives in one place can break.

!
Design Warning

If your business depends on per-key ordering or per-key state, choose your partition count generously at the start. Changing it later is a migration project, not a routine setting change.

Keys with no ordering need

If events do not need to be grouped by any key, producers can leave the key empty. Kafka then spreads events across partitions in a balanced way, using a strategy that fills batches per partition before moving to the next. For such topics, changing partition count later is much safer because no business rule depends on the mapping.

Topic StyleOrdering NeedEffect of Adding Partitions Later
Keyed, ordered per entityStrict per keyRisky: key mapping changes and order can break
Keyed, stateful processingState lives with the keyRisky: state may be in the wrong place
Unkeyed, independent eventsNone across eventsSafe: events spread across the new partitions
Compacted, latest value per keyLatest wins per keyNeeds care: the same key may exist in two partitions

5The Throughput Method: Sizing With Simple Math

The most widely used starting point is a short calculation that compares what you need with what one partition can do.

The core idea

Suppose you want a topic to handle a target throughput, which is the amount of data per second the whole topic must carry. You measure or estimate two numbers. The first is how much one partition can absorb on the write side. The second is how much one partition can be processed on the read side by a single consumer. Then you divide the target by each number and take the larger result.

1

Define the target throughput

Estimate the peak data rate the topic must carry, in megabytes per second, not the daily average. Include the expected growth over the next one to two years.

2

Measure per-partition write capacity

Run a small test with your real message sizes and settings to see how much a single partition can absorb. Real numbers beat rules of thumb.

3

Measure per-partition read and processing capacity

Test how fast one consumer can read and finish its real work for a partition, including database calls or network requests it makes for each event. This number is often much smaller than the write number.

4

Divide and take the larger

Target divided by write capacity gives one number. Target divided by read capacity gives another. The bigger of the two is the minimum partition count.

5

Add headroom for growth and spikes

Multiply by a safety factor that reflects expected growth, uneven key distribution and future consumer scaling.

A worked example in words

Imagine a payments topic that must carry a peak of one hundred megabytes per second. Testing shows a single partition can accept about twenty megabytes per second on the write side. A single consumer, because it calls a fraud-scoring service for every event, can only process five megabytes per second. Dividing the target by the write capacity gives five. Dividing by the consumer capacity gives twenty. The larger value is twenty, so the topic needs at least twenty partitions to keep up. Notice that the slow consumer, not the broker, decided the answer.

i
Insight

In most real systems the consumer side is the bottleneck because consumers do real work with each event. Measure your slowest processing step honestly. Many teams plan for the broker and then discover the consumer needed three times more partitions.

Simple Analogy

A factory has trucks that can deliver raw material quickly, but the assembly workers are slow. The number of assembly stations should be decided by how fast workers can build, not by how many trucks arrive. Otherwise materials pile up at the gate.

Why peak matters more than average

Averages hide the busiest moments. A shopping platform may run at a modest rate all week and then receive ten times more events during a sale. If partitions are sized for the average, consumers fall behind during the peak and lag grows. Plan for the peak you must survive, and then check how quickly consumers can catch up afterwards.

Turning throughput into events per second

Some teams find it easier to think in events per second instead of megabytes. Multiply events per second by average event size to get data rate. Small events cost more per byte because of overhead, while very large events strain memory and network buffers. Always use realistic event sizes from production samples, including the slowest and largest cases.

6Planning for Consumers, Headroom and Growth

A good partition count leaves room to add consumers later without touching the topic.

Start from the maximum consumer count

Ask how many consumer instances your largest group may ever need. This includes peak season, catch-up after downtime, and future features. Your partition count should be at least that number. If you might one day run thirty consumers, thirty partitions is the floor, not the ceiling.

Choose numbers that divide nicely

When partitions are shared among consumers, even splits make life easier. Twelve partitions can be evenly divided among two, three, four or six consumers. Thirteen partitions cannot be evenly split by any of those. Numbers with many divisors, such as twelve, twenty-four or forty-eight, give flexibility when consumer counts change. This is not a hard rule, but it reduces the situation where one consumer carries an extra partition and becomes the slow one.

Factor 1

Peak Throughput

The highest data rate the topic must carry, including spikes and growth.

Factor 2

Consumer Speed

How fast one consumer can finish real work for its partitions.

Factor 3

Maximum Consumers

The largest number of parallel readers you may ever want in a group.

Factor 4

Ordering Rules

Whether events must stay together by key, which limits later changes.

Factor 5

Cluster Capacity

How many partitions your brokers can carry comfortably in total.

Factor 6

Growth Horizon

How long the number must stay valid before a planned redesign.

How much headroom is enough?

There is no universal answer, but many teams plan for twice to three times the current need when ordering makes later changes painful. For unkeyed topics where increasing later is safe, they start closer to the current need and grow when metrics say so. The right multiplier depends on how costly a change would be for your specific system.

Simple Analogy

When buying a school uniform for a growing child, you choose a size a little large so it fits next year too. Buy exactly today’s size and it will not fit in a few months. Buy a giant size and the child trips over it. The best choice is a small, deliberate margin.

!
Common Mistake

Planning only for today’s consumers. A team ships with four partitions because four consumers are enough now, and then a new feature triples the processing cost per event. There is no room to scale, and the fix requires a risky partition migration.

7The Hidden Costs of Too Many Partitions

Every partition is a small, permanent commitment for the cluster. Here is what each one costs.

Open files and disk structures

Each partition on a broker is stored as a directory of log segment files, and each segment has companion index files. Kafka keeps many of these files open so it can serve reads and writes quickly. More partitions mean more open file handles on each broker, and operating systems have limits. Running out of file handles leads to failures, so brokers with many partitions need carefully raised limits.

Memory on brokers and clients

Producers keep a memory buffer for batches destined to each partition they write to. If a producer talks to thousands of partitions, its memory use grows, and batches get smaller, which lowers efficiency. Consumers, likewise, reserve fetch buffer space per assigned partition. A consumer that owns hundreds of partitions may need much more memory than one that owns ten.

Replication traffic

Every partition has followers that continuously fetch from the leader. With a replication factor of three, each partition creates two follower streams. Thousands of partitions produce thousands of tiny fetch streams between brokers. Even when data volume is low, this bookkeeping consumes network and processing time.

Controller and metadata load

One component in the cluster, the controller, manages partition leadership and metadata. It decides which replica is leader for each partition and informs the other brokers of changes. More partitions mean more metadata to store, transmit and update. Modern Kafka versions, which manage metadata with their own internal quorum instead of an external coordination service, handle far more partitions than older versions, but the cost never becomes zero.

Advantages of More Partitions

  • Higher potential write throughput across brokers
  • More consumers can read in parallel
  • Smaller units of data to move when rebalancing the cluster
  • Better spreading of load and storage
  • Room for future growth without redesign

Disadvantages / Trade-offs

  • More open files, memory and network connections
  • Longer recovery after a broker failure or restart
  • Higher end-to-end latency in some situations
  • Smaller producer batches and lower efficiency
  • More metadata for the controller and clients to track
“A partition is cheap to create and expensive to live with.”
i
Practical Tip

Look at your total partition count across all topics, including replicas, divided by the number of brokers. That per-broker figure is the number that tells you how heavy the cluster really is. Compare it with the guidance for your Kafka version and hardware.

8Availability, Recovery and Latency

Partition count changes how the cluster behaves when things go wrong, and how fast data feels.

What happens when a broker fails

When a broker stops, every partition whose leader lived on that broker needs a new leader chosen from its in-sync followers. This election must happen for each affected partition. If a broker was leading a thousand partitions, a thousand elections must complete before all those partitions are available again. During that time, producers and consumers of those partitions may see errors or pauses.

sequenceDiagram
  participant B as Broker 1
  participant C as Controller
  participant F as Follower Brokers
  participant K as Clients
  B-->>C: Broker stops responding
  C->>C: Find partitions led by Broker 1
  C->>F: Promote in-sync followers to leaders
  F-->>K: Clients discover new leaders
  K->>F: Resume reads and writes
        
FIG 4 — After a failure, each affected partition needs a new leader, so more partitions mean more recovery work

Restart and recovery time

During a planned restart or after an unclean crash, a broker must load its partitions and bring followers back in sync. More partitions, and more segment files inside them, lengthen this process. Rolling upgrades, where brokers restart one after another, take longer as the partition count per broker grows.

Latency

A record is considered safely committed only after in-sync followers have copied it. A follower broker handles many partitions with limited fetch threads. As the number of partitions per broker rises, each partition gets attention less often, and the time for followers to catch up can increase. For most workloads the effect is small, but for latency-sensitive systems it can matter.

Simple Analogy

A single delivery driver can handle a handful of packages quickly. Give the same driver a thousand small parcels going to a thousand addresses, and even if the total weight is the same, the total delivery time grows because of all the stops.

Failure blast radius

Interestingly, more partitions can also make failures gentler in one way. If a topic’s load is spread across many partitions on many brokers, losing one broker removes a smaller share of the work. The trade-off is between a smaller share lost per failure and a larger amount of recovery work per failure. Planning means finding the balance that suits your availability goals.

!
Watch Out

Unbalanced leadership can turn a partial failure into a serious one. If one broker holds a much larger share of leaders than others, its failure creates a large surge of elections and load on the survivors.

9Changing Partition Count Later

You can grow a topic, but you cannot shrink it, and growing has side effects you must understand in advance.

Increasing is allowed, decreasing is not

Kafka lets administrators add partitions to an existing topic. It does not let anyone remove partitions from a topic. If you overshoot, the only way back is to create a new topic with fewer partitions and move the data and applications over to it. That is why planning matters: adding is easy, undoing is hard.

What adding partitions does and does not do

New partitions start empty. Existing data is not moved into them. Only new events flow into the new partitions according to the current mapping. For unkeyed topics this simply spreads future load. For keyed topics, as discussed earlier, the mapping of keys to partitions changes, which can disturb ordering and state.

flowchart LR
  subgraph Before["Before: 3 partitions"]
    A0["P0: key K1 history"]
    A1["P1"]
    A2["P2"]
  end
  subgraph After["After: 6 partitions"]
    B0["P0: old history"]
    B1["P1"]
    B2["P2"]
    B3["P3 new"]
    B4["P4 new"]
    B5["P5 new"]
  end
  Before --> After
  B3 -. "K1 may now land here" .-> B0
        
FIG 5 — After adding partitions, new events for a key may go to a different partition than its history

The safer migration path

When a keyed topic truly needs more partitions, the safest method is usually to create a new topic with the desired count, run producers so they write to the new topic, let consumers drain the old topic fully, and then move consumers over. This avoids key mixing across old and new partitions. It needs coordination, time and often a brief period of dual running, which is why teams prefer to choose well the first time.

1

Create the new topic

Choose the improved partition count using updated measurements and the same retention and replication rules.

2

Redirect producers

Switch producers to write to the new topic, ideally at a moment when a clean cut-off point can be identified.

3

Drain the old topic

Let existing consumers finish processing everything remaining in the old topic so no older event is left behind.

4

Move consumers and retire the old topic

Point consumers to the new topic, confirm health, and only then remove the old topic according to your retention needs.

i
Tip

Ask early whether a topic is keyed and stateful. If yes, treat the initial partition count as a long-term decision and involve every team that consumes the topic in the planning conversation.

10Spreading Partitions Across Brokers and Fighting Skew

The right number of partitions is useless if the load lands unevenly on the machines.

Partitions per broker

Kafka places partition leaders and replicas across brokers, trying to balance them. For balance to work, the partition count should be comfortably larger than the broker count. A topic with three partitions on a ten-broker cluster uses only three brokers for its leaders. If you want a topic to use the whole cluster, the partition count should be a multiple of the broker count or at least several times larger.

Data skew and hot partitions

Skew means some partitions receive far more data than others. It happens when keys are unevenly distributed. If one customer generates half of all events and the key is the customer ID, one partition becomes a hot spot, and its consumer falls behind while others sit idle. Adding more partitions does not help because that one customer still maps to one partition.

Simple Analogy

A bank with ten counters, where a single giant company insists on sending all its accountants to counter number four. The other nine counters are quiet, while counter four has a huge queue. Building more counters will not fix the problem unless the company’s traffic is spread out.

Ways to reduce skew

Choose a better key

Pick a key with many evenly used values, such as an order ID instead of a country code. A key with only a few possible values can never spread across many partitions.

Add a small suffix to hot keys

For the rare extremely busy key, add a small variable part so its events spread across a few partitions. This gives up strict order for that key, so use it only when the business can accept that.

Use a custom partitioning rule

Producers can use their own rule to choose partitions, for example sending known heavy customers to dedicated partitions. This requires careful documentation because every producer must follow the same rule.

Monitor per-partition size and rate

Watch how evenly bytes and events are distributed. A partition that is much larger than its peers is an early warning sign.

!
Common Mistake

Assuming partition count solves imbalance. Partition count gives capacity, but key design gives balance. Both are needed.

11Storage and Retention Planning

Partition count interacts with disk space, retention time and the cost of moving data.

How storage is divided

The total storage a topic needs equals its data rate multiplied by its retention time, multiplied again by the replication factor. This total is shared across all partitions. More partitions do not create more total data, but they divide it into more, smaller pieces. Each partition lives entirely on one broker per replica, so a single partition cannot be larger than the disk space available on the broker that hosts it.

Keeping partitions a manageable size

Very large partitions are hard to move. If one partition holds terabytes of data, then rebalancing it to a new broker, or rebuilding a lost replica, takes a long time and consumes lots of network bandwidth. Very small partitions are easy to move but add overhead. Many teams aim for partitions that stay within a size where recovery and movement finish in a reasonable time window that matches their availability targets.

Rate
bytes per second written
Retention
how long data is kept
Replicas
number of copies stored
Simple Analogy

Moving house is easier with many small boxes than with a few enormous crates that no one can lift. But too many boxes mean endless trips and lost labels. Choose a box size that people can carry without back pain and that still keeps the number of boxes reasonable.

Retention and compaction effects

Topics with long retention keep old segments for a long time, so file counts and disk usage stay high. Topics with log compaction, which keep only the latest value per key, run background cleaning work per partition. Cleaning threads are a shared resource, so having a very large number of compacted partitions can slow the cleaning and delay space reclaim.

i
Tip

Calculate storage per broker, including all replicas, and keep generous free space. A cluster running near full disks has very little ability to recover from a broker loss, no matter how well partitions were counted.

12Special Situations That Change the Math

Some workloads follow extra rules, and partition planning should take them into account.

Stream processing applications

Stream processing frameworks that read from Kafka often create one task per input partition. The number of partitions in the input topics therefore sets the maximum parallelism of the application. When an application reads from several topics and joins them, those topics must usually have matching partition counts and matching key rules so related events meet in the same task.

Stateful processing and local storage

Applications that keep local state, such as running totals per customer, attach that state to a partition. If the partition count changes, the state may no longer match the new key mapping. This is another strong reason to plan generously when stateful processing is involved.

Transactions and exactly-once processing

Transactions allow a set of writes across partitions to succeed or fail together. They add coordination cost that grows with the number of partitions touched in one transaction. Designs that write to a huge number of partitions in each transaction can slow down, so consider grouping related data on fewer partitions when using transactions heavily.

Connectors and data integration

Data integration tools that copy data between Kafka and databases usually parallelise by partition on the Kafka side and by table or range on the other side. The number of tasks they can run is limited by partitions, so a sink connector reading a topic with two partitions will never use more than two tasks effectively.

Very small or very slow topics

Configuration topics, audit trails or rarely updated reference data may have tiny volumes. A single partition, or a few, is often perfectly fine. Giving them dozens of partitions adds overhead with no benefit. The same rule applies to dead-letter topics that hold rare failed events.

Workload

Stream Processing

Partitions set the maximum number of parallel tasks. Joined topics need matching counts.

Workload

Stateful Apps

State is tied to key mapping, so plan generously and avoid later changes.

Workload

Transactional Writes

Coordination cost grows with partitions touched per transaction.

Workload

Low-volume Topics

Few partitions are enough. Extra partitions only add overhead.

13Security, Quotas and Governance

In a shared cluster, partition count is also a governance question, not just a technical one.

Why governance matters

In a company with many teams sharing one Kafka cluster, any team that can create topics can also create partitions. One team choosing very high partition counts for many topics can quietly consume a large share of the cluster’s capacity and hurt other teams. Treat partition count as a shared resource, like disk space or network bandwidth.

Practical controls

Restrict topic creation

Use access control rules so that only approved tools or people can create topics or add partitions. Disable automatic topic creation in production so a typing mistake does not create an unplanned topic with default settings.

Set organisation limits

Define a maximum partition count per topic and per team unless a request is reviewed. Some platforms also support limits on the rate of topic and partition changes, which protects the controller from sudden bursts.

Use quotas for clients

Client quotas limit how much bandwidth a producer or consumer may use. They protect neighbours when one application is heavy, and they complement partition planning by preventing a single client from monopolising capacity.

Keep a topic catalogue

Record the owner, purpose, expected throughput, key choice and partition rationale for each topic. Future teams can then understand why a number was chosen before they attempt to change it.

i
Governance Tip

Ask every topic request to include the expected peak throughput, the number of consumers, and the ordering need. If the owner cannot answer these questions, the topic is not ready to be created.

14Monitoring: Knowing When Your Number Is Wrong

Planning gives you a starting point. Monitoring tells you if reality agrees.

Consumer lag

Consumer lag is the difference between the newest event in a partition and the position of the consumer group. Lag that grows steadily during normal traffic means consumers cannot keep up. If adding consumers helps, and you still have free partitions, the plan is fine. If all partitions are already taken and lag persists, your partition count is limiting you.

Per-partition throughput and size

Track bytes in and out per partition, and the size on disk. Compare the busiest partition with the average. A large gap points to skew. Comparing total traffic with the number of partitions shows how much room you still have.

Broker health signals

Watch the number of partitions per broker, the count of leaders per broker, request handler idle time, network thread usage, open file handle usage, and under-replicated partitions. A rising count of under-replicated partitions during normal operation suggests brokers are struggling to keep up with replication, sometimes because of too many partitions.

Controller and recovery timing

Measure how long leader elections and broker restarts take. Record these times after each cluster change. If restarts take significantly longer than they used to, partition growth may be the reason.

SignalWhat It Tells YouPossible Partition Action
Steadily growing consumer lagConsumers cannot keep paceAdd consumers, or add partitions if all are in use
One partition far larger than othersKey skewImprove key design rather than adding partitions
Under-replicated partitions risingReplication cannot keep upReview partitions per broker and network capacity
Slow broker restartsHeavy recovery workloadReduce partitions per broker or add brokers
Many idle consumersMore consumers than partitionsReduce consumers or plan increase in partitions
Simple Analogy

Monitoring is like the fuel gauge, temperature light and speedometer in a car. You planned the trip, but you still check the dashboard to know if something needs attention before the engine stops.

15Design Patterns and Anti-Patterns

Patterns that work well, and the traps that catch even experienced teams.

Patterns worth adopting

Plan from measurements, not from folklore

Run small tests with real message sizes and real consumer work to determine per-partition capacity. Record the results in the topic catalogue so later decisions build on evidence.

Standard tiers of topics

Define a few standard sizes, for example small, medium and large, with agreed partition counts and replication settings. Teams choose a tier instead of inventing numbers, which keeps clusters predictable.

Over-provision keyed topics slightly

For topics with per-key ordering or state, choose a partition count with headroom so you never need the risky migration.

Start modest on unkeyed topics

For topics where order across events does not matter, start with a reasonable count and grow based on metrics, since growing is safe.

Anti-patterns to avoid

ANTI-PATTERN-01 Avoid
Problem

Creating every topic with the same large default number of partitions, such as one hundred, “just in case”.

Why It’s Harmful

Hundreds of low-traffic topics with a hundred partitions each quickly add up to a huge total. Brokers carry unnecessary files, memory and replication streams, and restarts and elections get slow.

Correct Approach

Size each topic according to its own throughput and consumer needs. Give small topics small counts and reserve large counts for genuinely busy topics.

ANTI-PATTERN-02 Avoid
Problem

Launching a keyed topic with the minimum number of partitions and planning to “just add more later”.

Why It’s Harmful

Adding partitions changes key mapping. Ordering guarantees and local state can break, and the fix becomes a difficult, coordinated migration under production pressure.

Correct Approach

Choose a generous count for keyed topics at the beginning, based on future consumers and throughput, and document the reasoning.

ANTI-PATTERN-03 Avoid
Problem

Choosing a key with very few distinct values, such as a country code or a status field.

Why It’s Harmful

A handful of keys can only fill a handful of partitions, however many exist. Most partitions stay empty while a few are overloaded.

Correct Approach

Use a key with many evenly used values, or leave the key empty when ordering is not needed.

ANTI-PATTERN-04 Avoid
Problem

One topic per tiny customer or per user, resulting in tens of thousands of topics with several partitions each.

Why It’s Harmful

The total partition count explodes and the controller and brokers are overloaded, while each topic carries almost no traffic.

Correct Approach

Use a shared topic with the customer or user ID as the key, so the number of partitions stays under control.

16A Repeatable Planning Workflow

Put everything together into a simple procedure any team can follow for a new topic.

flowchart TD
  S["New topic request"] --> Q1{"Is per-key order or state needed?"}
  Q1 -- "Yes" --> K["Plan generously: change later is risky"]
  Q1 -- "No" --> U["Plan closer to need: growth later is safe"]
  K --> M["Measure write and consumer capacity"]
  U --> M
  M --> C["Compute: target divided by capacity, take the larger"]
  C --> H["Add headroom and align to consumer counts"]
  H --> L{"Within cluster limits?"}
  L -- "No" --> R["Review design, add brokers, or reduce"]
  L -- "Yes" --> D["Document reasoning and create topic"]
  R --> H
  D --> W["Monitor lag, skew and broker health"]
        
FIG 6 — A decision flow for choosing the partition count of a new topic
1

Gather requirements

Collect peak throughput, message size, retention, consumer count, ordering rules and the growth horizon from the owning team.

2

Classify the topic

Decide if it is keyed and stateful, keyed only, or unkeyed. This tells you how careful the first choice must be.

3

Measure and compute

Test per-partition write and consumer capacity, then divide the target by each and take the larger number.

4

Apply headroom and choose a friendly number

Add a margin for growth and skew, and round to a number with many divisors so consumer counts can change smoothly.

5

Check against cluster limits

Add the new partitions and their replicas to the current total per broker. If the cluster would exceed comfortable limits, plan capacity first.

6

Document and review

Write down the inputs and the reasoning in the topic catalogue, and schedule a review after the first busy period.

i
Habit Worth Building

Revisit partition decisions after real traffic arrives. The first plan is an educated estimate, and the review turns it into knowledge for the next topic.

17Best Practices and Common Mistakes

A quick reference of what to do and what to avoid.

Best Practices

  • Plan from measured per-partition capacity
  • Consider the slowest consumer step, not only the broker
  • Choose counts with many divisors, like twelve or twenty-four
  • Give keyed and stateful topics extra headroom
  • Keep total partitions per broker within tested limits
  • Document why each count was chosen
  • Review after real traffic arrives

Common Mistakes

  • Sizing for the average instead of the peak
  • Ignoring consumer processing time
  • Adding partitions to a keyed topic without a plan
  • Using the same big default for every topic
  • Assuming more partitions fix skewed keys
  • Forgetting that replicas count toward broker load
  • Leaving automatic topic creation on in production
!
Reminder

The most expensive partition mistakes are the ones you cannot reverse quickly: shrinking a topic, or changing a key mapping after data and state exist. Spend planning time where reversal is hardest.

Simple Analogy

A carpenter measures twice and cuts once because wood cannot be un-cut. Partition counts on keyed topics are the same. A little extra measuring at the start saves a great deal of repair later.

18Real-World Scenarios

Four common situations show how the same principles lead to different partition decisions.

Scenario 1: E-commerce order events

An online store publishes every order change to a topic keyed by order ID, so all updates to one order stay in sequence. Traffic doubles during festival sales, and fulfilment, billing and analytics groups all read the topic. Planners size for the sale peak, add headroom for future consumers, and choose a highly divisible count. Because order IDs are numerous and evenly used, skew is low.

Scenario 2: Sensor data from devices

A fleet of connected devices sends readings every few seconds. The topic is keyed by device ID to keep each device’s readings in order. Volume is steady but high, and processing is light. Broker write capacity is the limiting factor, so the throughput calculation on the write side decides the count, with extra room as more devices are added.

Scenario 3: Payments with slow fraud checks

A payments topic feeds a consumer that calls an external fraud service for each event. The consumer is slow, so consumer capacity drives the count. The team needs many parallel consumers, and thus many partitions, even though the byte rate is modest. They also keep per-account ordering by keying on account ID.

Scenario 4: Application audit log

A small internal system writes a few events per minute to an audit topic that one consumer reads. There is no ordering across events and no growth expected. The team chooses a very small partition count, saving cluster resources without any downside.

ScenarioMain Driver of CountKey ChoiceHeadroom Approach
E-commerce ordersPeak sale throughputOrder IDGenerous, for later consumers
Device sensorsBroker write capacityDevice IDGrow with device fleet
PaymentsSlow consumer processingAccount IDGenerous, ordering matters
Audit logMinimal needNoneLittle headroom needed

What large organisations do

Companies that operate Kafka at very large scale usually build internal platforms around these ideas. They offer standard topic templates, automated checks on requested partition counts, dashboards for lag and skew, and regular reviews of clusters with too many partitions per broker. The common thread is that partition count is treated as a managed, reviewed resource and not as a casual default.

19Frequently Asked Questions

Q1Is there one correct number of partitions for every topic?

No. The right number depends on throughput, consumer speed, ordering needs and cluster capacity. Two topics in the same cluster often deserve very different counts.

Q2Can I have more consumers than partitions?

You can start them, but within one consumer group the extra consumers will sit idle. They are useful only as standby replacements if an active consumer fails.

Q3Can I reduce the number of partitions later?

No. Kafka only allows increasing partitions. To end up with fewer, you must create a new topic and migrate producers and consumers to it.

Q4What happens to my data when I add partitions?

Existing data stays where it is. New partitions begin empty and receive only new events. For keyed topics, the mapping of keys to partitions changes for new events.

Q5Does a higher partition count always increase throughput?

Only up to the point where other limits take over, such as disk speed, network bandwidth, consumer processing or broker overhead. Beyond that, extra partitions add cost without adding speed.

Q6Why does ordering only work inside a partition?

Each partition is an independent log handled by its own leader. Coordinating order across many independent logs would slow everything down, so Kafka guarantees order only where it is cheap and reliable.

Q7Do replicas count as partitions when I think about cluster limits?

Yes for load purposes. Each replica is stored and served by a broker, so a topic with ten partitions and three replicas creates thirty partition copies across the cluster.

Q8Should the partition count match the number of brokers?

Not necessarily, but a count that is a multiple of the broker count helps spread leaders evenly. A topic with fewer partitions than brokers cannot use every broker for leadership.

Q9What if my topic has no key?

Then Kafka spreads events across partitions on its own, and changing the count later is much safer. You can start with a moderate number and grow when metrics show the need.

Q10How do I know if I chose too few partitions?

Signs include persistent consumer lag even after adding consumers to the limit, single brokers saturated on writes, and inability to scale processing because every partition already has its own consumer.

Q11How do I know if I chose too many partitions?

Signs include slow broker restarts, long leader elections, high memory use in clients, many empty or nearly empty partitions, and very high partition counts per broker compared with your tested limits.

Q12Is it wise to create a topic per customer?

Rarely. A large number of tiny topics multiplies partitions and overwhelms the cluster. A shared topic keyed by customer ID usually meets the need with far fewer partitions.

20Summary and Key Takeaways

Partition count planning is the art of giving a Kafka topic enough lanes to carry its traffic and its readers, without paying for lanes it will never use. A partition is the basic unit of storage, replication and parallel reading, so this single number shapes throughput, ordering, recovery time and cost. The best plans combine measured numbers, honest attention to slow consumers, generous thinking for keyed and stateful data, and steady monitoring after launch.

If you remember only one sentence, let it be this: adding partitions later is possible but disruptive for keyed data, and removing them is impossible, so think carefully at the start and review with real traffic.

Key Takeaways

  • Partitions are the unit of parallelism — a consumer group can use at most as many active consumers as there are partitions in the topic.
  • Order exists only inside a partition — keys keep related events together only while the partition count stays fixed.
  • Use the throughput method — divide the peak target by per-partition write capacity and by per-partition consumer capacity, then take the larger result and add headroom.
  • The slow consumer often decides — measure real processing time, because consumer speed frequently sets the count more than the brokers do.
  • Partitions have a cost — open files, memory, replication traffic, controller work, slower recovery and possible latency all grow with the count.
  • Growth is one-way — you can add partitions but never remove them, and adding to keyed topics changes key mapping, so plan generously up front.
  • Balance and monitor — good keys prevent skew, standards and governance protect shared clusters, and lag, skew and broker health metrics tell you when to adjust.