Consumer Groups and Rebalancing
Understand how Kafka consumer groups scale consumption, how partitions are assigned, and what happens during a rebalance, with Spring Kafka in mind.
Consumer Groups and Rebalancing is a free Advanced Spring Boot 4: Event-Driven Architecture (Kafka) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Advanced Spring Boot 4: Event-Driven Architecture (Kafka) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Consumer Groups?
A consumer group lets multiple consumer instances share the work of reading a topic. Kafka assigns each partition to exactly one consumer in the group.
Group ID
Consumers join a group by sharing a group.id. Kafka tracks the offset position per group, so each group reads the topic independently.
spring.kafka.consumer.group-id=order-servicePartitions Drive Parallelism
The number of partitions sets the maximum parallelism. With four partitions, at most four consumers in a group can work at once.
topic orders: 4 partitions
group with 4 consumers -> 1 partition eachExtra Consumers Idle
If a group has more consumers than partitions, the extras sit idle. Scale partitions to scale consumption beyond the current limit.
6 consumers, 4 partitions -> 2 idleWhat Triggers a Rebalance
A rebalance reassigns partitions when group membership changes.
- A consumer joins or leaves
- A consumer is considered dead
- Partitions are added
Rebalance Cost
During a rebalance, consumers stop processing briefly while partitions are reassigned. Frequent rebalances hurt throughput.
Heartbeats and Liveness
Consumers send heartbeats. Missing them past session.timeout.ms marks a consumer dead and triggers a rebalance.
session.timeout.ms = 10000
heartbeat.interval.ms = 3000Poll Loop Health
If processing between polls exceeds max.poll.interval.ms, the consumer is evicted. Keep per-message work bounded or increase the limit.
max.poll.interval.ms = 300000Committing Offsets
Offsets record progress per partition per group. Spring Kafka can auto-commit or commit manually after successful processing for at-least-once delivery.
spring.kafka.consumer.enable-auto-commit=falseCooperative Rebalancing
The cooperative rebalance protocol reassigns only the partitions that must move, avoiding a full stop-the-world reassignment.
partition.assignment.strategy=CooperativeStickyAssignorSpring Kafka Listeners
A @KafkaListener joins the configured group automatically; running multiple app instances scales the group with no code change.
@KafkaListener(topics = "orders", groupId = "order-service")
void onOrder(Order o) { ... }Quick Check
Reason about parallelism.
Recap
You learned that a consumer group shares a topic by assigning each partition to one consumer, so partition count caps parallelism. Rebalances reassign partitions when membership changes and briefly pause processing; heartbeats and poll intervals govern liveness. Cooperative rebalancing and manual offset commits keep Spring Kafka consumers efficient and reliable.
Frequently asked questions
Is the “Consumer Groups and Rebalancing” lesson free?
Yes — the full text of “Consumer Groups and Rebalancing” is free to read here on the web, and the Advanced Spring Boot 4: Event-Driven Architecture (Kafka) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Advanced Spring Boot 4: Event-Driven Architecture (Kafka) course, upgrade to CoddyKit PRO.
What will I learn in “Consumer Groups and Rebalancing”?
Understand how Kafka consumer groups scale consumption, how partitions are assigned, and what happens during a rebalance, with Spring Kafka in mind. You practise Advanced Spring Boot 4: Event-Driven Architecture (Kafka) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?
No prior experience is required. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Consumer Groups and Rebalancing” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Advanced Spring Boot 4: Event-Driven Architecture (Kafka) lesson?
Yes. Every Advanced Spring Boot 4: Event-Driven Architecture (Kafka) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Kafka Architecture Overview
- Topics, Partitions, and Offsets
- Setting up Local Kafka with Docker
- Consumer Groups and Rebalancing