I recently had an interesting conversation exploring a common Kafka question: Why can't you reduce the number of partitions in a Kafka topic?
It turns out that Kafka deliberately does not support reducing partition counts, and the reason is deeply tied to how it guarantees ordering and data integrity.
The Core Problem: Data is Already Distributed
When you produce messages, Kafka distributes them across partitions (either via a key hash or round-robin). Each partition holds an ordered, immutable log of offsets. If you reduce partitions from, say, 6 to 3, Kafka would have to answer a dangerous question: what happens to the data in the removed partitions?
There are only two logical options, and both are unsafe:
- Delete it: Results in unacceptable data loss for a durable log system.
- Merge it: Violates offset integrity. Consumers track progress via offsets (e.g., partition=2, offset=105). Merging would invalidate all committed offsets, breaking consumer groups irreversibly.
Furthermore, Kafka only guarantees ordering within a partition, not across them. Merging independent ordered logs into one would interleave messages with no deterministic ordering, completely destroying producer intent.
How Scaling Actually Works in Kafka
Scaling in Kafka is asymmetric. Scaling up is easy; scaling down is a process.
Scaling Up (Adding Capacity)
- Adding Partitions: You can increase partitions anytime (
kafka-topics --alter). However, if you use key-based hashing, this reassigns keys and can temporarily break ordering for specific keys until consumers catch up. - Adding Consumers: If you have more partitions than consumer instances, spinning up more consumers triggers a rebalance, smoothly assigning idle partitions to new members.
- Adding Brokers: You can add new servers to the cluster and use the
kafka-reassign-partitionstool to transfer existing replicas to new hardware.
Scaling Down (Reducing Capacity)
Since you can't just "hit a button" to reduce partitions, here is the safe approach:
- Removing consumers: Safe and automatic. Kafka detects a consumer leaving, triggers a rebalance, and redistributes remaining partitions to active instances.
- Removing brokers: Requires manual reassignment of partitions away from the broker first. Only after leadership and replicas are moved can you safely shut it down.
- Reducing partitions: Not supported. Your only option is to create a new topic with fewer partitions and migrate your consumers.
The Practical Scaling Pattern
Because of this asymmetry, teams typically follow these standards:
- Over-partition at creation: Provision more partitions than you need today (e.g., 10–20x expected peak parallel consumption). This gives you headroom to scale consumers up later.
- Scale consumers elastically: Add/remove consumer instances freely within the partition ceiling. This is where true elasticity lives in Kafka!
- Scale brokers for throughput/storage: Add brokers and reassign partitions to spread the underlying load.
- Treat partition count as a schema decision: Choose it carefully upfront, like a database schema. Changing it later is costly.
Ultimately, a helpful mental model is this: Brokers control storage and throughput. Partitions set your parallelism ceiling. Consumers represent your actual, elastic parallelism operating within that ceiling.