Infrastructure advanced LIVE DEMO
βš–οΈ

Kafka Partition Rebalancing Lifecycle Visualization

Walk through the Kafka Partition Rebalancing lifecycle with guided steps for group coordinator, partition assignment, rebalance, consumer lag, heartbeat.

kafkarebalancingconsumer groupconsumer lagpartition assignmentdistributed systemsvisualization
Interactive Demo

Continue with the guided workspace

Use the paired workspace to connect this guide's mental model with live component state, visible signals, and the outcome each step or scenario is meant to prove.

Mental Model

Kafka partition rebalancing is the mechanism by which the cluster maintains high read availability when group membership changes. When a consumer joins, leaves, crashes, or fails to send heartbeats, Kafka coordinates a rebalance to redistribute partition ownership. While rebalancing is necessary to share the workload, it introduces consumer lag and latency spikes during the pause phase.

Components and Why They Exist

Heartbeat Monitor and Topic Partitions (P0–P5)

The heartbeat monitor tracks liveness across the consumer group while topic partitions P0–P5 hold the ordered event streams being consumed. When a member’s session timeout expires or a new consumer joins, unconsumed records accumulate as visible partition lag until the rebalance completes and fetchers resume.

Group Coordinator (Broker 1)

The Group Coordinator (Broker 1) is the broker responsible for managing the consumer group’s state and coordinating rebalances. It receives member heartbeats, detects consumer timeouts, elects the group leader, and initiates the JoinGroup and SyncGroup protocol whenever Consumer 3 stops sending heartbeats.

Consumers (Consumer 1, 2, 3)

Consumers 1, 2, and 3 are the worker instances within the consumer group that pull data in parallel from assigned partitions. Each consumer periodically sends heartbeats to the coordinator, handles rebalance signals, commits offsets, and transitions its card status badge between active fetching, rebalancing, and failed states.

Assignment Strategy

The assignment strategy decides how partitions are distributed among active group members. It calculates partition-to-consumer mappings (using Range, Round Robin, or Cooperative Sticky rules) based on active consumer counts and maps topic partitions P0–P5 onto the surviving consumer cards.

Offset Commit Tracker

The offset commit tracker records partition progress during consumer handoff. It safely commits the last processed offsets before releasing partition ownership so the next owner does not reprocess already committed records when the group stabilizes.

Rebalance Barrier

The rebalance barrier coordinates the stop-the-world synchronization phase of an eager rebalance. It halts partition fetching across the group until all active consumers have rejoined the barrier and received their updated partition assignments.

Edge Cases and Misconceptions

  • Misconception: Rebalancing is always fast and harmless: Under classic Eager Rebalancing, all consumers must stop reading entirely, causing complete consumption halts (stop-the-world pauses). For large clusters, this can cause significant consumer lag.
  • Misconception: Range assignment is always the best strategy: Range assignment allocates contiguous partitions per topic, which can cause severe consumer load imbalance if topics have differing partition sizes. Round Robin or Sticky assignment is better for even distribution.
  • Edge Case: Rebalance Storm (Consumer Flapping): If a consumer is overloaded and experiences long garbage collection pauses, it may fail to send heartbeats, triggering a rebalance. When it recovers, it rejoins, triggering another rebalance. This loop is called a rebalance storm.
  • Edge Case: Cooperative Sticky Rebalancing: Modern Kafka clients use Cooperative Sticky protocol, which only revokes and reassigns partitions that are actually moving, allowing unchanged assignments to continue processing during the rebalance.

Open the Kafka Partition Rebalancing simulator sandbox after the walkthrough when you want to experiment with consumer scale, failure timeouts, assignment strategies, and partition workloads.

Common Questions

What is a consumer group rebalance in Kafka?

A rebalance is the process where a cluster coordinator redistributes partition assignments among the active members of a consumer group when group membership or partition counts change.

What is the difference between Range and Round Robin assignment strategies?

Range strategy assigns contiguous segments of partitions to each consumer (e.g. C1 gets P0-P2). Round Robin interleaves partition assignments (e.g. C1 gets P0, C2 gets P1, C3 gets P2, C1 gets P3), which balances partitions more evenly.

Why does a rebalance halt consumer traffic?

During an eager rebalance, consumers must stop fetching data, commit their current offsets, and rejoin the group to receive new assignments. This prevents multiple consumers from reading the same partitions concurrently, but introduces processing pauses.

How does consumer flapping lead to a rebalance storm?

If a consumer is unstable (flapping due to garbage collection pauses, network drops, or hardware issues), it repeatedly leaves and rejoins the group. Each status change triggers a rebalance, keeping traffic halted and causing partition lag to balloon.