Scrivio Interview library
InternalsFoundations7 min read · updated 12 November 2026

Explain how a Kafka consumer group assigns partitions to consumers and what happens during a rebalance. A topic has 6 partitions and a Spring @KafkaListener has concurrency = 3 in each of 4 pods. How many consumers actually receive data?

Try it yourself

Consumer group: who reads which partition

Change the number of partitions and consumers, and see who owns what, who is idle, and where ordering holds.

Read this example as text

Who reads which partition

  1. 3 partitions, 2 consumers. C0 reads P0, P1; C1 reads P2.
  2. 4 partitions, 2 consumers. C0 reads P0, P1; C1 reads P2, P3.
  3. 3 partitions, 3 consumers. C0 reads P0; C1 reads P1; C2 reads P2.
  4. 6 partitions, 4 consumers. C0 reads P0, P1; C1 reads P2, P3; C2 reads P4; C3 reads P5.
  5. 2 partitions, 4 consumers. C0 reads P0; C1 reads P1; C2 is idle; C3 is idle.

A partition has exactly one reader in the group. A consumer beyond the number of partitions is idle.

Six records with 3 partitions and 2 consumers

  1. Record A1. Key A goes to P0, read by C0.
  2. Record B1. Key B goes to P1, read by C0.
  3. Record A2. Key A goes to P0, read by C0.
  4. Record C1. Key C goes to P2, read by C1.
  5. Record B2. Key B goes to P1, read by C0.
  6. Record A3. Key A goes to P0, read by C0.

A1, A2 and A3 sit in one partition and are read in that order. Nothing orders a record in one partition against a record in another.

What this example leaves out
  • One topic, and Kafka's range assignor, the first in the default list. Other assignors spread partitions differently.
  • A, B and C stand for key hashes 0, 1 and 2. The real client hashes the key bytes; the rule shown, same key to the same partition, is the same.
  • A rebalance is shown as instant. In a real group, consumers stop briefly while partitions move.

Within a consumer group, each partition is assigned to exactly one consumer, so a group can never have more active consumers than the topic has partitions. Four pods with concurrency 3 create 12 consumers, but the topic has only 6 partitions, so only 6 consumers receive data and the other 6 sit idle. A rebalance reassigns partitions when members join, leave, or miss heartbeats or max.poll.interval.ms; the classic eager protocol revokes everything first, the cooperative sticky assignor moves only what must move, and Kafka 4 makes the broker-driven consumer group protocol of KIP-848 generally available.

Why this question is asked

Scaling consumers is one of the first things teams try when a Kafka topic falls behind, and it often does nothing. Interviewers ask this question because the answer needs a clear model of how a group shares partitions and of what a rebalance costs, and the arithmetic catches people who think concurrency always adds throughput. In this answer, we will recap consumer groups, do the calculation for the question's setup, walk through what triggers a rebalance, compare the eager, cooperative and new broker-driven protocols, and see how static membership helps during rolling restarts.

1A Quick Recap of Consumer Groups

A topic is split into partitions, ordered logs that are the unit of parallelism in Kafka. Consumers that share the same group.id form a consumer group, and together they consume the topic once: each partition is assigned to exactly one member of the group at a time, so each record is processed by one member. A consumer may own several partitions, but a partition is never shared between two members of the same group. That one rule explains the whole question: the number of partitions is the ceiling on how many consumers in one group can do useful work.

In Spring Kafka, a @KafkaListener with concurrency = 3 creates a ConcurrentMessageListenerContainer with three child containers, and each child has its own KafkaConsumer and its own thread. So each pod contributes three group members, not one.

2Doing the Arithmetic

Four pods each start three consumers, all in the same group, so the group has 4 x 3 = 12 members. The topic has 6 partitions. The assignor hands one partition to each of 6 members and nothing to the remaining 6. Those idle consumers still poll, send heartbeats and take part in every rebalance, but they never receive a record.

Java
@KafkaListener(topics = "orders", groupId = "billing", concurrency = "3")
public void onOrder(OrderEvent e) { ... }
// 4 pods x 3 consumers = 12 group members
// 6 partitions -> 6 members get 1 partition each, 6 members get none
// Which 6? It depends on the assignor: possibly all 3 consumers of pod A and none of pod D
Possible assignment of 6 partitions to 12 consumers
PodConsumer threadsPartitions received
pod-ac1, c2, c3p0, p1, p2
pod-bc4, c5, c6p3, p4, p5
pod-cc7, c8, c9none (idle)
pod-dc10, c11, c12none (idle)
One possible outcome; the assignor may spread the 6 partitions differently, but only 6 members ever work.

Notice the last comment. The assignment is by member, not by pod, so the work may be spread unevenly between pods, with some pods fully idle. If we want 12 consumers to work, the topic needs at least 12 partitions. If 6 partitions are enough, then 2 pods with concurrency 3, or 3 pods with concurrency 2, would do the same work with fewer idle resources.

3What Triggers a Rebalance

A rebalance is the process of recomputing which member owns which partition. It happens when the group's membership or the topic changes. A new member joins, such as a pod starting. A member leaves cleanly, such as a pod shutting down. A member is considered dead, either because it stopped sending heartbeats for longer than session.timeout.ms (45 seconds by default in recent clients), or because it did not call poll() within max.poll.interval.ms (5 minutes by default), which means its processing is stuck or too slow. Partitions are added to a subscribed topic, or a new topic matches a pattern subscription.

While partitions are being moved, the affected ones are not consumed, and the offsets that the old owner had processed but not committed will be processed again by the new owner. So frequent rebalances mean lost throughput and duplicate processing.

4Eager, Cooperative and the New Protocol

With the classic eager protocol, used by the range and round-robin assignors, every rebalance starts by every member revoking all its partitions. The group then waits for all members to rejoin, the leader computes a new assignment and everyone starts again. For a short moment, nobody in the group consumes anything, even if only one partition needed to move. This is often called a stop-the-world rebalance.

The cooperative sticky assignor, CooperativeStickyAssignor, makes rebalances incremental. Members keep the partitions they will still own and only give up the ones that must move, which happens over two short rounds. Consumption of unaffected partitions continues. Recent Java clients include it in the default assignor list alongside the range assignor, and Spring Kafka uses whatever the client is configured with.

Kafka 4 goes further and makes the new consumer group protocol from KIP-848 generally available. We opt in with group.protocol=consumer. The group coordinator on the broker computes assignments itself, and each member learns its changes through its regular heartbeat, so there is no group-wide synchronisation barrier and rebalances are incremental by design. Client-side assignor settings do not apply in this mode; a server-side assignor is used instead. Check that your brokers and Spring Kafka version support it before enabling it.

Properties
# Spring Boot, classic protocol with incremental rebalances
spring.kafka.consumer.properties.partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor
# Kafka 4 brokers and clients: the new broker-driven protocol (KIP-848)
spring.kafka.consumer.properties.group.protocol=consumer
Rebalance styles compared
StyleWhat movesWho computes the assignment
Eager (range, round-robin)all partitions revoked, then reassignedgroup leader, a client
Cooperative stickyonly partitions that change ownergroup leader, a client
KIP-848 consumer protocolonly partitions that change ownergroup coordinator on the broker

5Static Membership for Rolling Restarts

During a rolling deploy, each pod stops and starts again. Normally, the stop makes the consumer leave the group, triggering one rebalance, and the start makes it join, triggering another. With four pods and three consumers each, a deploy can cause many rebalances in a few minutes.

Static membership changes this. We give each consumer a stable group.instance.id, for example built from the pod name and the thread index. A static member that shuts down does not send a leave request, and the coordinator keeps its partitions reserved until session.timeout.ms expires. If the same instance id comes back within that time, it simply gets its old partitions back with no rebalance at all. The trade-off is that if a pod dies for good, its partitions wait for the session timeout before moving, so we set the timeout a little longer than a normal restart, for example 60 to 90 seconds.

6Follow-up questions

How would static membership (group.instance.id) help during rolling restarts?

It lets a restarting consumer rejoin under the same identity without triggering a rebalance. A static member that stops does not leave the group; the coordinator holds its partitions until session.timeout.ms passes. If the pod is back within that window with the same group.instance.id, it resumes its old partitions directly. Other members never stop or move partitions, so a rolling deploy of four pods causes no rebalances instead of eight. The instance id must be unique per consumer, so with concurrency 3 we include the thread index, and the session timeout must be longer than a typical restart but short enough that a truly dead pod's partitions are reassigned in acceptable time.

Would increasing the partition count to 12 fix the idle consumers?

Yes, all 12 consumers would then get one partition each. But adding partitions to an existing keyed topic changes which partition each key maps to, which breaks per-key ordering during the transition. If ordering by key matters, it is safer to create the topic with enough partitions from the start, or to reduce the number of consumers to match.

7Conclusion

In this answer, we saw that a consumer group assigns each partition to exactly one member, so 4 pods with concurrency 3 give 12 consumers of which only 6 receive data from a 6-partition topic. Rebalances happen when members join, leave, or miss heartbeats or max.poll.interval.ms. The eager protocol revokes everything first, the cooperative sticky assignor moves only the partitions that change owner, Kafka 4 makes the broker-computed KIP-848 protocol generally available, and static membership avoids rebalances during rolling restarts.

What to say in the interviewAbout 90 seconds aloud

Open with

In a consumer group, each partition is owned by exactly one consumer at a time, so the partition count is the upper limit on active consumers. In Spring Kafka, concurrency 3 means three KafkaConsumer instances per pod, each a separate group member, so four pods give twelve members.

Then, if they want more

With six partitions, six members get one partition each and the other six are idle. And it is per member, not per pod, so a whole pod could end up idle.

A rebalance reassigns partitions when a member joins or leaves, when it misses heartbeats for longer than session.timeout.ms, or when it does not call poll within max.poll.interval.ms, and also when partitions are added. With the classic eager protocol every member revokes all partitions first, so the whole group pauses.

The cooperative sticky assignor makes it incremental: members keep what they still own and only the moved partitions pause. Kafka 4 makes the KIP-848 consumer protocol generally available with group.protocol=consumer, where the broker's group coordinator computes assignments and members get changes through heartbeats, so there is no global barrier.

For rolling restarts I would add static membership with a stable group.instance.id per consumer, so a pod that comes back within the session timeout gets its partitions back without a rebalance. And for this setup I would either reduce consumers to six or increase partitions, keeping in mind that adding partitions changes key placement.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain how a Kafka consumer group assigns partitions to consumers and what happens...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/647663ff41/

More in Apache Kafka with Spring