Kafka Partition Strategies: Scaling Consumers Without Reshuffling Everything
Picking partition counts and keys decides whether your Kafka consumers scale linearly or hit a wall. The patterns that survived rebalances, partition-count changes, and consumer-group ops.
Key takeaways
- Kafka partitions cap consumer parallelism, since a group gets at most one active consumer per partition, and they define ordering, which holds only within a partition.
- Size for peak throughput and two to three times today's consumer count, key by the entity that needs ordering, and avoid adding partitions later, because it remaps keys.
On this page
Pick a Kafka partition count for peak throughput and two to three times your current consumer count, because a consumer group can't run more active consumers than partitions. Key messages by the entity that needs ordering, since order holds only within a partition. Avoid adding partitions later: it remaps keys and breaks per-key ordering for stateful consumers.
Verified againstChecked against official docs
Apache Kafka 4.4.0 (released 2026-10-22), KEDA 2.21, against the kafka.apache.org 4.4 producer and consumer config reference, the consumer rebalance protocol and upgrade notes, and the KEDA Apache Kafka scaler docs. Checked October 2026.
The two things partitions actually control
Partitions decide two things and only two:
- Maximum consumer parallelism within a consumer group. A topic with 12 partitions can be processed by at most 12 consumers in the same classic group. Add a 13th and it sits idle.
- Ordering guarantees. Within a partition, Kafka guarantees order. Across partitions there is none: messages with key A and key B can reach consumers in either relative order.
Every other consideration (throughput, durability, retention) flows from those two.
Sizing rule that actually works
"Pick lots of partitions" is half right and half misleading. The rule we use:
partitions = max( peak_target_throughput_MB_per_sec / per_partition_throughput_MB_per_sec,
expected_max_consumers )
Per-partition throughput depends on hardware, message size, replication and how fast your consumer processes each record, so measure it rather than borrowing someone else's number. Run kafka-producer-perf-test.sh and kafka-consumer-perf-test.sh against a single-partition test topic on your own brokers. If one partition sustains 5 MB/s, you expect a 50 MB/s peak, and you might want 8 parallel consumers, pick max(10, 8) = 10.
Common mistakes:
- Way too few. A topic with 3 partitions caps consumer parallelism at 3. Hard to fix later without pain.
- Way too many. 1,000 partitions on a topic with 100 KB/s of traffic. Each partition costs broker memory and file handles, and thousands of tiny partitions slow recovery and bloat KRaft metadata (ZooKeeper mode was removed in Kafka 4.0).
We aim for "headroom for 2-3x current consumer count, sized for peak throughput, rounded to a number you'll remember": typically 6, 12, 24, or 48, not 7 or 19.
Key choice = ordering policy
The key decides the partition. With the default partitioner, a keyed message goes to hash(key) mod num_partitions (murmur2 in the Java client). So:
- Same key, same partition, ordered relative to each other.
- Different keys, possibly different partitions, no order guarantee between them.
This is the most under-thought decision in Kafka design. What do you actually need ordered?
For an order-processing service, probably "events for the same order_id." Key on order_id. For a user-event tracker, key on user_id. For application logs, usually nothing needs ordering: send a null key and the producer spreads records with its sticky partitioner, switching partition after each batch rather than per message.
The biggest mistake here is keying on something coarse, like tenant_id in a multi-tenant SaaS, when most tenants are small and one is huge. All the big tenant's traffic lands on one partition.
The hot partition problem
You key by tenant_id. Tenant 42 produces 80% of the traffic. Its partition is the bottleneck while the others idle. You scaled to 12 partitions hoping for 12x throughput and got a fraction of that.
Three real fixes:
- Add randomness to the key. Key =
tenant_id + ":" + random_bucket(0..N-1), which spreads tenant 42 across N partitions. Trade: messages for the same tenant are no longer strictly ordered, which may or may not matter. - Custom partitioner. Detect hot tenants and route them across more partitions. Most Kafka clients support one. More code, more control.
- Per-tenant topics for huge tenants. A dedicated topic for tenant 42, handled specially by consumers. Works for "a few whales," not for many.
We reach for (1) most often. It is an explicit concession in ordering in exchange for real parallelism.
Changing partition counts is painful
Adding partitions is technically easy (kafka-topics.sh --alter --partitions). Doing it without breaking things isn't.
Because placement is hash(key) mod num_partitions, a new count sends many existing keys to a different partition. Events for the same user can now land on a different consumer than before, and any consumer state keyed by partition is stale.
What we do:
- Pick a partition count up front and stick with it. The cheapest answer.
- If we must add partitions: stop consumers, let them drain, change the count, restart, and accept a one-time reshuffle.
- Never add partitions on a live topic where consumers keep per-partition or per-key state without coordinating.
"Just add partitions later" works for stateless consumers. Anything stateful, you pay later.
Consumer group sizing
A consumer group should have:
- One consumer per partition for max parallelism.
- Fewer, if your consumers are fast enough to handle several partitions each.
- No more than partitions. Extras sit idle in a classic group. (Kafka 4.2 made share groups, "Queues for Kafka," production-ready; they let more consumers than partitions share work, but give up per-partition ordering.)
For autoscaling consumer pools, scale on consumer lag, not CPU. A consumer that's keeping up looks fine on CPU; lag tells the real story. We use KEDA's Apache Kafka scaler. Its lagThreshold is the target total lag (default 10, so set it deliberately), and by default it won't scale past the topic's partition count unless you set allowIdleConsumers.
Rebalance pain
When a consumer joins or leaves a classic group, Kafka rebalances. With the eager protocol, every consumer stops, the assignment is recomputed, and partitions are handed out again. That pause can be milliseconds for small groups or seconds for large ones with heavy state.
Mitigations:
session.timeout.ms(default 45 seconds, classic protocol): how long a consumer can go silent before it's declared dead. Longer means fewer rebalances on blips and slower detection of real failures.max.poll.interval.ms(default 5 minutes): the maximum gap between polls. If processing a batch takes longer, the consumer is kicked out and the group rebalances. Tune to your real processing time plus margin, or lowermax.poll.records.- Cooperative rebalancing.
CooperativeStickyAssignormoves only affected partitions. The Java default is[RangeAssignor, CooperativeStickyAssignor], so removeRangeAssignorto actually use it. - The new consumer protocol. KIP-848 has been GA since Kafka 4.0. Set
group.protocol=consumerand the broker assigns partitions incrementally without a group-wide synchronization barrier. It's opt-in on the client, andsession.timeout.msandpartition.assignment.strategyno longer apply under it.
"Consumer keeps getting kicked out of the group" is almost always max.poll.interval.ms: processing took longer than expected and the group assumed the consumer died.
Specific patterns we run
- Idempotent producers.
enable.idempotence=trueandacks=allhave been the producer defaults since Kafka 3.0; verify nothing in your config overrides them. - Manual commit on consumers (
enable.auto.commit=false, since the default istrue). Commit after successful processing, not on poll. - Dead letter topic for messages that fail processing. After N retries, ship to a separate topic for human triage.
- Compaction for state-like topics (latest value per key wins). Useful for change data capture and config distribution.
What we monitor
- Consumer lag per partition. The most important metric. Growing lag means consumers can't keep up; per-partition lag surfaces hot partitions.
- Under-replicated partitions on the brokers. Indicates broker health issues.
- Rebalance rate. Healthy is near zero.
- Message size distribution. Sudden growth can quietly tip a partition past its capacity.
Questions people ask
How many partitions should a Kafka topic have?
Take the larger of two numbers: peak throughput divided by what one partition sustains on your hardware, and the most consumers you expect to run in one group. Then add headroom of two to three times today's consumer count and round to something like 6, 12, 24 or 48. Measure per-partition throughput with the bundled perf-test scripts instead of trusting published figures.
Can I have more consumers than partitions in Kafka?
In a classic consumer group, no: each partition goes to one consumer and extras sit idle. KEDA's Kafka scaler caps replicas at the partition count by default for that reason. Share groups, production-ready since Kafka 4.2, let more consumers than partitions split work from one topic, at the cost of per-partition ordering, so they suit job-queue workloads.
What happens when you add partitions to a Kafka topic?
Existing data stays where it is, but new messages are placed with the new partition count, so many keys map to a different partition than before. Ordering per key breaks across the change, and consumers holding per-partition or per-key state see keys arrive somewhere new. For stateful consumers, stop, drain, alter the count, then restart.
What to read next
- Job queues: Sidekiq, Celery, BullMQ patterns, the adjacent pattern when Kafka is overkill
- Pipeline observability: why CI failures don't trigger alerts, the same observability discipline applied to CI
- Multi-provider LLM routing: failover, cost, load balancing, partition-like fan-out applied to LLM APIs
Most Kafka issues trace back to one of three decisions: wrong partition count, wrong key, or an unanticipated hot tenant. Get those right at design time and Kafka is one of the most predictable parts of the stack.
Sources
Cite this article
Kiril Urbonas (2026). Kafka Partition Strategies: Scaling Consumers Without Reshuffling Everything. DevOpsNess. Updated 2026-11-20. https://www.devopsness.com/blog/kafka-partition-strategies-scaling-consumers
[Kafka Partition Strategies: Scaling Consumers Without Reshuffling Everything](https://www.devopsness.com/blog/kafka-partition-strategies-scaling-consumers) (Kiril Urbonas, DevOpsNess, updated 2026-11-20)
More from DevOps
Explore more articles in this category
Event-Driven Architecture: The Complete Guide
Synchronous calls couple your services together and fail together. Events let systems react instead of ask. This is the map: the patterns, the messaging tools, and the delivery guarantees that make it work.
Dependency Scanning and SCA: A Practical Guide
A practical look at how SCA scanning finds vulnerable dependencies, cuts CVE noise, and where SAST, DAST, and IAST fit into CI/CD.
Burn-Rate Alerting: The SLO Discipline That Prevents Alert Fatigue
Static thresholds and cause-based alerts produce noisy pages. Burn-rate alerting asks "are we burning the error budget faster than we can sustain?" and pages only when users are actually hurting.
You might have missed
Evergreen posts worth revisiting.