liveBook · Manning

Consumer group rebalancing

As explained in Kafka for Architects

Consumer group rebalancing is the redistribution of topic-partition assignments among consumer group members when membership or partition availability changes.

A consumer service processing customer profiles and transactions may run several instances for capacity and resilience. If one instance fails, its partitions still need a processor; if another starts, the workload may need redistributing. Consumer group rebalancing is Kafka’s reassignment of partitions among group members when membership changes. Within a group, each partition is assigned to only one consumer at a time. section 4.0 section 4.2.7

A rebalance can follow several membership changes:

  • A new consumer joins, potentially spreading partitions across more instances. section 4.2.7
  • A consumer leaves gracefully, fails, or becomes too slow; its partitions are reassigned to healthy members. section 4.2.7
Figure 4.11 Redistribution of the partitions after a failure
A screenshot of a diagram

Description automatically generated

The before-and-after partition assignment makes the failure case concrete: remaining consumers take over the failed instance’s partitions. section 4.2.7

Rebalancing preserves processing capacity after a failure, but it has a cost. An eager rebalance temporarily stops processing for all consumers, revokes their partitions, and assigns partitions again. The group coordinator manages membership and facilitates rebalances; a group leader manages partition assignments in coordination with it. section 4.2.7 section 4.7

Scaling a streaming application

Several Kafka Streams instances can share a group ID and process partitions from input topics. If an instance fails, its partitions move to active instances. Adding instances does not create unlimited parallelism: the number of input partitions limits how many instances can process them concurrently. section 8.1.2

Avoid treating every rebalance as useful. For temporary restarts, static membership gives each consumer a unique group.instance.id; if it rejoins within session.timeout.ms, it can retain its previous assignments. Long-running record processing may also require tuning max.poll.interval.ms and max.poll.records. Heartbeat and session timeouts balance prompt failure detection against unnecessary rebalances. Benchmark these settings against the application’s processing workload rather than choosing them solely for fast failover. section 4.2.8 section 4.3.3

How Kafka for Architects covers it

How deep it goes
Explains triggers, eager-rebalance interruption, static membership, and timeout tuning; does not detail the rebalance protocol.
Examples
Illustrates reassignment after consumer failure with a partition diagram and a multi-instance Kafka Streams application.
What it assumes
Builds on consumers, topics, partitions, and group membership, defining their assignment relationship before discussing redistribution.
What you can do after
Operate/configure consumer groups to limit avoidable rebalances while retaining failure detection and partition takeover.
How it connects
Connects partition assignment and consumer groups to group coordinators, static membership, consumer timeouts, and Kafka Streams scaling.

Also explained in

Compare how 3 books explain consumer group rebalancing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka for Architects. The section links point to the parts of the book it draws on.