Blog
Kafka partitions and consumer groups
How Kafka splits a topic into partitions, shares them across a consumer group, tracks offsets and lag, and rebalances when consumers join or leave.
· 6 min read
Partitions, consumer groups, offsets and rebalances are the four words you meet first in Apache Kafka, and they're really one idea: how Kafka splits a stream of records into pieces, hands each piece to one reader, and remembers how far each reader got. This post explains that idea in plain words and pictures, using one example topic called orders.
Every fact here was checked against the Apache Kafka 4.4 documentation on 2026-10-31; the sources are listed at the end.
A topic is split into partitions
A topic is a named stream of records, such as orders. Kafka doesn't store a topic as one long list. It splits it into partitions and spreads them across the brokers in the cluster, so many machines can share the work.
Each partition is an append-only log. A new record always goes on the end, and it gets the next number in that partition: its offset. Offsets start at 0 and count up separately in every partition.
Kafka keeps order inside a partition: every consumer reads a partition's records in exactly the order they were written. There's no single order across partitions, so record 4 in P0 isn't "before" or "after" record 4 in P2.
Reading a record doesn't remove it. Records stay in the partition until the topic's retention settings remove them, or, on a compacted topic, until a newer record with the same key replaces them. So you can read the same topic as often as you need, with as many readers as you need.
The key decides the partition
A producer can send each record with a key, such as a customer or order ID. With the default settings, the producer hashes the key to choose the partition, so records with the same key always go to the same partition. That's how you keep every event for one customer in order.
Records without a key are spread across partitions. By default the producer sends them to one partition until at least batch.size bytes have gone there, then switches to another.
A consumer group shares the work
Consumers that use the same group.id form a consumer group. Kafka assigns each partition to exactly one consumer in the group, so each record is handled by one member of the group, not by all of them.
Groups are independent of each other. A second group reading the same topic gets every record too, and keeps its own position. That's how a service that updates orders and an analytics job can both read orders without getting in each other's way.
How many consumers a group can use
Because a partition goes to only one consumer in a group, the number of partitions is the most consumers a group can keep busy.
- Fewer consumers than partitions: some consumers read more than one partition.
- As many consumers as partitions: each consumer reads one partition.
- More consumers than partitions: the extra consumers get no partition. They can take over if another member leaves, but until then they read nothing.
So if a group can't keep up and every consumer already has a single partition, adding consumers won't help. You need more partitions, or faster processing per record.
Offsets: how a group remembers where it stopped
For each partition it reads, a consumer tracks a position: the offset of the next record it will read. From time to time it commits that position to Kafka. Kafka stores committed offsets per group and partition in an internal topic called __consumer_offsets. By default, enable.auto.commit is true and the consumer commits in the background every 5 seconds (auto.commit.interval.ms).
If a consumer restarts, or its partition moves to another consumer, reading continues from the committed offset. Any records it processed after its last commit are read again, so make processing safe to repeat.
Lag is the gap between the log-end offset (where the next record will be written) and the group's committed offset. You can see it per partition with the tool that ships with Kafka:
kafka-consumer-groups.sh --bootstrap-server broker:9092 \
--describe --group orders-projectorA group with no committed offset for a partition, or whose committed offset no longer exists, starts where auto.offset.reset says: latest by default, which reads only new records, or earliest to start from the oldest record still kept. The Kafka docs warn that latest can silently skip records when partitions are added: producers can write to a new partition before the group finds it, and latest starts after those records. They suggest by_duration:<duration> instead, which starts from records written within that time before now, such as by_duration:PT6M with the classic protocol. To move a group that already has offsets, see how to reset consumer offsets safely.
Rebalancing: when the group changes
The assignment isn't fixed. A broker acts as the group's coordinator, and the group rebalances, moving partitions between members, when:
- a new consumer joins the group,
- a consumer shuts down or fails,
- the number of partitions of a subscribed topic changes,
- a subscribed topic is created or deleted.
How Kafka notices a consumer is gone
A consumer sends heartbeats in the background. If they stop for longer than session.timeout.ms (45 seconds by default), Kafka considers it dead and gives its partitions to the others.
There's a second check. If your code doesn't call poll() again within max.poll.interval.ms (5 minutes by default), the consumer leaves the group itself so another member can take over. Slow processing of one batch is a common cause of rebalances nobody expected.
Everyone pauses, or only what moves
In the classic protocol, how a rebalance feels depends on the assignor:
- Eager: every consumer gives up all its partitions before the rebalance, so the whole group stops reading until it's done.
RangeAssignorworks this way. - Cooperative: consumers keep the partitions they already own, and only the ones that need to move are handed over.
CooperativeStickyAssignorworks this way.
The default partition.assignment.strategy is RangeAssignor, CooperativeStickyAssignor. It uses range, and lets you move to cooperative with a single rolling restart that removes RangeAssignor from the list.
The newer consumer protocol
Since Apache Kafka 4.0, a newer rebalance protocol (KIP-848) is production-ready. It's fully incremental, with no group-wide pause, and the broker chooses the assignment, with uniform (the default) and range assignors built in. Clients opt in with group.protocol=consumer; the default is still classic. With it, the client can't set session.timeout.ms, heartbeat.interval.ms or partition.assignment.strategy; the broker's group.consumer.* settings take their place.
Fewer rebalances on restart
Set group.instance.id to a stable ID for each consumer instance and it becomes a static member. Together with a longer session timeout, a restart that's back within that timeout, such as one step of a rolling deploy, doesn't trigger a rebalance.
Seeing it in Offvio
Offvio's consumer group view shows each partition's committed offset, end offset and lag, with the group's members and the partitions each one owns. The Distribution tab shows message, size and leader skew across partitions, so you can spot a hot partition before its consumer falls behind.


More on cluster operations in Offvio and monitoring lag.
Recap
- A topic is split into partitions; order is kept only inside a partition.
- The key decides the partition, so the same key always lands in the same place.
- In a consumer group, each partition has exactly one consumer. Extra consumers sit idle.
- Each group keeps its own committed offsets, and lag is how far it is behind.
- When members come and go, the group rebalances. Cooperative assignors and the newer protocol move only what needs to move.
Sources
- Introduction: topics, partitions, keys and ordering.
- Design: consumer position and consumer groups.
- KafkaConsumer: group membership, rebalance triggers, heartbeats and
max.poll.interval.ms. - Consumer configs and producer configs: defaults quoted in this post.
- RebalanceProtocol: eager and cooperative rebalancing.
- Consumer rebalance protocol: the newer protocol (KIP-848).
- Basic operations: adding partitions and
__consumer_offsets. - Apache Kafka 4.2.0 release announcement: share groups production-ready.