0Pricing
Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · Lesson

Rebalance Listeners and Static Membership

Learn how consumer group rebalances disrupt processing and how rebalance listeners plus static membership minimize downtime and state loss.

Rebalance Listeners and Static Membership 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.

What Triggers a Rebalance

A rebalance reassigns partitions among consumers in a group. It happens when a consumer joins, leaves, crashes, or its session times out.

During a rebalance, processing pauses across the group.

The Cost of Rebalancing

Frequent rebalances hurt throughput: partitions are revoked and reassigned, in-flight work may be reprocessed, and local caches are invalidated.

Advanced consumers actively minimize and react to rebalances.

Rebalance Listener Hooks

A ConsumerRebalanceListener gives you two callbacks:

  • onPartitionsRevoked — called before partitions are taken away.
  • onPartitionsAssigned — called after new partitions are granted.

Committing on Revoke

Use onPartitionsRevoked to commit offsets for work completed so far, avoiding duplicate processing after reassignment.

public void onPartitionsRevoked(Collection<TopicPartition> parts) {
    consumer.commitSync(currentOffsets);
}

Wiring It in Spring

In Spring Kafka, implement ConsumerAwareRebalanceListener and set it on the container properties.

factory.getContainerProperties()
    .setConsumerRebalanceListener(myRebalanceListener);

Static Membership

Static membership assigns each consumer a stable group.instance.id. On a brief restart, the broker keeps its partitions instead of triggering a rebalance.

spring:
  kafka:
    consumer:
      properties:
        group.instance.id: consumer-pod-1

Session and Heartbeat Timeouts

Static membership relies on session.timeout.ms. If a consumer rejoins within the session window using the same instance id, no rebalance occurs.

session.timeout.ms: 45000
heartbeat.interval.ms: 3000

Cooperative Rebalancing

The CooperativeStickyAssignor reassigns only the partitions that must move, instead of revoking everything (stop-the-world). This dramatically reduces rebalance impact.

partition.assignment.strategy: org.apache.kafka.clients.consumer.CooperativeStickyAssignor

Avoiding Poll Timeouts

If processing a batch exceeds max.poll.interval.ms, the broker assumes the consumer is dead and rebalances. Keep per-poll work bounded or raise the interval.

Combining Strategies

For resilient consumers, combine static membership (avoid restart churn), cooperative rebalancing (smaller moves), and a rebalance listener (clean offset commits).

Putting It Together

Rebalances are unavoidable but controllable. Listeners let you commit cleanly, static membership avoids needless rebalances on restart, and cooperative assignment limits disruption.

Quick Check

Test your understanding of rebalancing.

Recap

You learned advanced rebalance handling.

  • Rebalances pause processing and can reprocess work.
  • Rebalance listeners let you commit offsets on revoke.
  • Static membership avoids rebalances on brief restarts.
  • Cooperative assignment reduces stop-the-world disruption.

Frequently asked questions

Is the “Rebalance Listeners and Static Membership” lesson free?

Yes — the full text of “Rebalance Listeners and Static Membership” 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 “Rebalance Listeners and Static Membership”?

Learn how consumer group rebalances disrupt processing and how rebalance listeners plus static membership minimize downtime and state loss. 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 “Rebalance Listeners and Static Membership” 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

  1. Manual Offset Committing
  2. Pausing and Resuming Consumers
  3. Concurrency and Thread Management
  4. Rebalance Listeners and Static Membership
← Back to Advanced Spring Boot 4: Event-Driven Architecture (Kafka)