Apache Kafka is widely used for building event-driven applications, distributed data pipelines, and real-time processing systems. It allows multiple consumer instances to process messages from a topic in parallel while maintaining partition-level ordering.

As an application grows, teams often increase the number of consumers to handle higher message volumes. They may also restart instances during deployments, replace unhealthy containers, or scale services automatically.

These changes can trigger a Kafka consumer group rebalance.

Rebalancing is an important part of Kafka's distributed architecture. It ensures that partitions are assigned to active consumers and that workload is distributed across the group.

However, rebalancing can temporarily interrupt message consumption. During certain types of rebalancing, consumers may need to release their current partition assignments and wait for the group to receive new assignments.

If rebalancing happens frequently, the application may experience processing pauses, increasing consumer lag and delaying downstream operations.

This article explains how Kafka consumer rebalancing works, why it causes processing pauses, what triggers repeated rebalances, and how to reduce their impact through better consumer configuration and deployment practices.

What Is Kafka Consumer Rebalancing?

Kafka stores messages in topics, and each topic is divided into partitions.

Partitions allow Kafka to distribute data across brokers and enable multiple consumers to process messages in parallel.

For example, consider an application that processes order events.

SQL
Topic: orders

Partition 0
Partition 1
Partition 2
Partition 3
Partition 4
Partition 5

A consumer group contains multiple consumer instances that work together to process these partitions.

Consider three consumers:

SQL
Consumer Group: order-processing-group

Consumer 1  ---> Partition 0, Partition 1
Consumer 2  ---> Partition 2, Partition 3
Consumer 3  ---> Partition 4, Partition 5

Each partition is assigned to one consumer within the group at a time.

Now suppose Consumer 3 stops unexpectedly.

Kafka must redistribute its partitions among the remaining consumers.

The new assignment might look like this:

Code
Consumer Group: order-processing-group

Consumer 1  ---> Partition 0, Partition 1, Partition 4
Consumer 2  ---> Partition 2, Partition 3, Partition 5

This reassignment process is called consumer rebalancing.

Kafka uses consumer group coordination to manage membership and partition ownership.

The purpose is to ensure that active consumers receive the appropriate partitions without assigning the same partition to multiple consumers in the same group at the same time.

Why Does Rebalancing Cause Processing Pauses?

Rebalancing can interrupt normal consumption because Kafka must coordinate changes in partition ownership.

The impact depends on the rebalance protocol and assignment strategy being used.

Full-stop rebalancing

With the traditional eager rebalance approach, consumers participating in a rebalance release their current partition assignments before receiving new assignments.

For example:

SQL
Before Rebalance

Consumer 1 ---> P0, P1
Consumer 2 ---> P2, P3
Consumer 3 ---> P4, P5

          Consumer 3 stops
                  |
                  v

Rebalance Starts

Consumer 1 ---> No partitions
Consumer 2 ---> No partitions

                  |
                  v

New Assignment

Consumer 1 ---> P0, P1, P4
Consumer 2 ---> P2, P3, P5

During the coordination process, consumers may temporarily stop processing records.

This can create a processing pause even when the remaining consumers are healthy.

The duration depends on factors such as group size, coordinator communication, consumer response times, and assignment complexity.

Incremental rebalancing

Cooperative rebalancing reduces unnecessary partition movement.

Instead of requiring every consumer to release all its partitions, Kafka can move only the partitions that need reassignment.

For example:

SQL
Before Rebalance

Consumer 1 ---> P0, P1
Consumer 2 ---> P2, P3
Consumer 3 ---> P4, P5

          Consumer 3 stops
                  |
                  v

Only Required Partitions Move

Consumer 1 ---> P0, P1, P4
Consumer 2 ---> P2, P3, P5

Existing assignments that do not need to change can remain in place.

This reduces the disruption associated with rebalancing.

However, cooperative rebalancing does not eliminate every processing pause. Consumers still need to revoke partitions that are being transferred and coordinate the new ownership.

Common Reasons Kafka Triggers a Rebalance

Understanding why rebalancing happens is more useful than simply increasing timeout values.

Several events can cause a consumer group to rebalance.

A consumer joins the group

When a new consumer instance joins an existing group, Kafka may redistribute partitions to include the new member.

Suppose a topic has six partitions and two consumers:

Code
Consumer 1 ---> P0, P1, P2
Consumer 2 ---> P3, P4, P5

A third consumer joins:

Code
Consumer 1 ---> P0, P1
Consumer 2 ---> P2, P3
Consumer 3 ---> P4, P5

The workload can now be distributed across three consumers.

However, adding consumers does not always improve throughput. The number of useful consumers is constrained by the number of partitions.

If a topic has six partitions, adding ten consumers to the same group does not allow all ten consumers to process that topic simultaneously. Some consumers will remain without assigned partitions.

A consumer leaves the group

A consumer may leave because of:

  • Application shutdown.

  • Container termination.

  • Deployment replacement.

  • Process crashes.

  • Network interruptions.

  • Health-check failures.

When a consumer leaves, Kafka must determine which remaining members should receive its partitions.

A controlled shutdown can help consumers release assignments cleanly.

However, an unexpected termination may require the group coordinator to detect that the member is no longer active.

A consumer fails to call poll() on time

This is one of the most important causes of unexpected rebalancing.

Kafka consumers must continue calling poll() to make progress in the consumer group protocol.

The max.poll.interval.ms setting defines the maximum allowed delay between poll() calls when using consumer group management.

If the consumer does not call poll() within this interval, Kafka considers it unable to make progress and may initiate a rebalance.

For example, consider a consumer with the following configuration:

Code
max.poll.interval.ms=300000

This allows up to five minutes between poll() calls.

Now imagine that the consumer retrieves 500 records and processes them sequentially.

If processing takes six minutes, the next poll() call occurs too late.

Kafka may consider the consumer failed, even if the application process is still running.

This is a common problem when message processing takes longer than expected.

Session timeout and heartbeat failures

Kafka consumers also use heartbeats to maintain group membership.

Under the classic group protocol, the consumer sends heartbeats to the group coordinator.

If the coordinator does not receive heartbeats within the configured session timeout, it can remove the consumer from the group.

For example:

Code
session.timeout.ms=45000
heartbeat.interval.ms=15000

These settings allow a 45-second session timeout with heartbeats sent every 15 seconds.

The exact permitted values depend on broker configuration and the consumer protocol.

A consumer may miss heartbeats because of:

  • Long garbage collection pauses.

  • Network interruptions.

  • CPU starvation.

  • Application process suspension.

  • Unresponsive consumer threads.

If the consumer is removed from the group, its partitions become available for reassignment.

An important distinction is that heartbeats and poll() serve different purposes.

Heartbeats help maintain group membership. poll() is also responsible for advancing the consumer's interaction with the application and group coordination.

A consumer can continue sending heartbeats while application processing is delayed, but exceeding max.poll.interval.ms can still cause it to leave the group.

Topic partition changes

A change in topic partition count can also trigger reassignment.

For example, an application may initially use four partitions:

Code
orders

P0
P1
P2
P3

Later, an administrator increases the partition count to eight.

Code
orders

P0
P1
P2
P3
P4
P5
P6
P7

The consumer group may need to rebalance to account for the additional partitions.

Topic subscriptions using patterns can also trigger re-evaluation when matching topics are added.

Subscription changes

If consumers change their topic subscriptions, Kafka may need to recalculate partition ownership.

For example, one consumer may initially subscribe to:

Code
orders

Later, the application changes its subscription to:

Code
orders
payments

The group assignment may need to change based on the updated subscription.

Avoid changing subscriptions unnecessarily in a long-running consumer application.

Understanding Kafka Partition Assignment Strategies

Kafka uses partition assignment strategies to decide which consumer receives each partition.

The assignment strategy affects how partitions are distributed and how much ownership changes during rebalancing.

RangeAssignor

RangeAssignor distributes partitions in ranges for each subscribed topic.

For example, consider six partitions and three consumers:

Code
Consumer 1 ---> P0, P1
Consumer 2 ---> P2, P3
Consumer 3 ---> P4, P5

This approach is straightforward, but it can produce uneven distribution across multiple topics depending on their partition counts and subscriptions.

RoundRobinAssignor

RoundRobinAssignor distributes partitions across consumers in a round-robin manner.

For example:

Code
Consumer 1 ---> P0, P3
Consumer 2 ---> P1, P4
Consumer 3 ---> P2, P5

It can produce a more even distribution when consumers subscribe to the same set of topics.

StickyAssignor

StickyAssignor attempts to balance partition assignments while preserving as many existing assignments as possible.

This reduces unnecessary partition movement when membership changes.

It is useful for applications where frequent partition movement can increase processing disruption.

CooperativeStickyAssignor

CooperativeStickyAssignor combines sticky assignment with cooperative rebalancing.

Instead of requiring all consumers to release every partition, it allows partitions to move incrementally.

For many applications using the classic consumer group protocol, it is a useful option for reducing rebalance disruption.

Comparing assignment strategies

Strategy

Assignment behavior

Rebalance characteristics

RangeAssignor

Assigns partitions in ranges

Can cause broader reassignment

RoundRobinAssignor

Distributes partitions in round-robin order

Can improve distribution across shared subscriptions

StickyAssignor

Preserves existing assignments where possible

Reduces unnecessary partition movement

CooperativeStickyAssignor

Preserves assignments and supports incremental movement

Reduces full-stop reassignment

For existing applications, review client and broker compatibility before changing assignment strategies.

Do not assume that changing the assignor alone will solve rebalances caused by slow processing or unstable consumer membership.

Reducing Processing Pauses With Cooperative Rebalancing

Cooperative rebalancing is one of the most effective ways to reduce unnecessary processing interruptions in consumer groups using the classic protocol.

In Java Kafka clients, you can configure CooperativeStickyAssignor:

Code
partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor

The cooperative approach allows consumers to retain partitions that do not need to move.

When ownership must change, the affected partitions are revoked and reassigned through incremental coordination.

This reduces the number of partitions that must stop processing during a rebalance.

However, cooperative rebalancing has important compatibility requirements.

All consumers participating in a group must support the selected protocol and assignment behavior.

A rolling migration from an eager assignor may require a staged configuration change so that group members agree on compatible assignment strategies.

Also, cooperative rebalancing is associated with the classic consumer group protocol. Kafka's newer consumer rebalance protocol uses a different, fully incremental coordination model.

Using Static Membership to Reduce Unnecessary Rebalances

Kafka normally treats consumers as dynamic group members.

When a consumer disconnects temporarily, Kafka may remove it from the group and reassign its partitions.

When the same application restarts, it joins again and may trigger another rebalance.

This can be disruptive during rolling deployments.

Static membership helps reduce unnecessary membership changes.

Under the classic consumer protocol, the group.instance.id configuration gives a consumer a stable identity.

For example:

Code
group.id=order-processing-group
group.instance.id=order-consumer-01

If the consumer temporarily restarts with the same identity, Kafka can treat it as the same logical group member rather than an entirely new member.

This can reduce rebalances caused by short-lived interruptions.

However, each static member ID must be unique within the group.

If two active consumers use the same group.instance.id, one can be fenced out.

Static membership also does not eliminate rebalancing when a member is permanently removed or when its partitions genuinely need to be reassigned.

It is most useful when consumer instances have stable identities and temporary restarts are expected.

Managing max.poll.interval.ms Correctly

Long-running message processing is a common reason for repeated rebalancing.

Consider this processing model:

Code
poll()
  |
  v
Receive 500 records
  |
  v
Process records sequentially
  |
  v
Database operations
  |
  v
External API calls
  |
  v
poll() again

If processing takes longer than max.poll.interval.ms, the consumer can be removed from the group.

There are several ways to address this.

Reduce the number of records returned per poll

The max.poll.records setting controls the maximum number of records returned by a single poll() call.

For example:

Code
max.poll.records=100

Reducing the batch size can reduce the time required to process each batch.

However, this setting does not change the underlying fetch behavior. The consumer may still fetch and cache records internally.

A smaller batch can also reduce throughput if processing has significant per-batch overhead.

Choose the value based on actual processing time.

Increase max.poll.interval.ms when justified

If processing legitimately takes longer, increase the maximum interval.

For example:

Code
max.poll.interval.ms=600000

This allows up to ten minutes between poll() calls.

However, increasing the interval is not a substitute for fixing an inefficient processing pipeline.

If processing time grows without limits, a larger timeout only delays the next rebalance.

Monitor processing duration and set the interval based on realistic worst-case behavior.

Separate polling from expensive processing

For workloads with long-running operations, avoid blocking the consumer's polling loop while waiting for every external operation to complete.

A common design is:

  1. Poll a controlled number of records.

  2. Submit records to a bounded processing mechanism.

  3. Continue polling within the required interval.

  4. Track the completion of each record.

  5. Commit offsets only after the corresponding work succeeds.

This approach requires careful offset management.

Kafka preserves ordering within each partition, and committing an offset too early can cause records to be skipped after a failure.

For example, if records from one partition are processed concurrently, record 12 might complete before record 11.

Committing offset 12 before record 11 finishes could cause the consumer to resume after both records following a restart.

Use per-partition processing coordination and commit only the highest contiguous sequence of successfully processed offsets.

For simpler applications, sequential processing with a suitably sized batch may be safer than introducing unnecessary concurrency.

Understanding the New Kafka Consumer Rebalance Protocol

Kafka has introduced a newer consumer group protocol designed to improve scalability and reduce the disruption associated with traditional rebalancing.

This protocol is commonly referred to as the Consumer rebalance protocol and is based on KIP-848.

It became generally available in Apache Kafka 4.0.

Unlike the classic protocol, the new protocol uses a fully incremental assignment process and does not rely on the same global synchronization barrier.

This can reduce rebalance times, especially for larger consumer groups.

Enabling the new protocol

For supported Kafka clients and brokers, the consumer can use:

Code
group.protocol=consumer

The classic protocol uses:

Code
group.protocol=classic

The new protocol also changes where certain configuration responsibilities live.

For example, when using the new consumer protocol:

  • Heartbeat interval configuration is controlled by the broker.

  • Session timeout configuration is controlled by the broker.

  • Partition assignment strategy configuration differs from the classic protocol.

  • Client-side assignment strategies are not supported in the same way as the classic protocol.

Do not copy classic consumer settings into a configuration using the new protocol without checking compatibility.

Classic versus new consumer protocol

Area

Classic protocol

New consumer protocol

Coordination

Classic group coordination

Next-generation group coordination

Assignment

Traditional assignment and cooperative options

Fully incremental assignment

Heartbeat configuration

Consumer-side settings

Broker-side settings

Session timeout

Consumer-side settings within broker limits

Broker-side settings

Assignment strategy

Client-side assignors

Broker-side assignors

Rebalance synchronization

Can involve a global synchronization barrier

Designed without the same global barrier

The new protocol is not automatically enabled simply because the broker supports it. The consumer configuration must opt into it, and the client must support the protocol.

Review the Kafka version, client library, broker configuration, and operational limitations before adopting it.

For an established application, test the protocol migration in a non-production environment before changing all consumers.

Handling Rebalances in Consumer Applications

Applications should handle partition assignment and revocation events explicitly.

In Java Kafka clients, ConsumerRebalanceListener provides callbacks that allow applications to respond when partitions are assigned or revoked.

For example:

Java
consumer.subscribe(
    List.of("orders"),
    new ConsumerRebalanceListener() {

        @Override
        public void onPartitionsRevoked(
            Collection<TopicPartition> partitions) {

            // Commit completed work.
            // Release partition-specific resources.
        }

        @Override
        public void onPartitionsAssigned(
            Collection<TopicPartition> partitions) {

            // Initialize partition-specific state.
        }
    }
);

The revocation callback is important because the application may need to complete outstanding work and commit offsets before losing partition ownership.

The assignment callback can be used to initialize state associated with newly assigned partitions.

Avoid performing lengthy operations inside rebalance callbacks. Delaying the coordination process can increase rebalance duration and affect other consumers.

The exact callback behavior depends on the selected protocol and client version. Cooperative rebalancing also requires careful handling of only the partitions being revoked rather than assuming that every assignment is removed.

Monitoring Kafka Consumer Rebalancing

Frequent rebalancing is not always obvious from application response times.

A consumer may continue processing messages while experiencing repeated assignment changes, but the pauses can cause lag to increase.

Monitor the following metrics:

Metric

What it indicates

Rebalance rate

How frequently rebalances occur

Rebalance latency

How long rebalances take

Consumer lag

How far consumers are behind the latest available records

Poll interval

Time between poll() calls

Records consumed

Consumer processing throughput

Heartbeat failures

Possible membership or connectivity problems

Partition assignment changes

Frequency of partition ownership changes

Processing duration

Time required to handle records

For Java Kafka clients, consumer metrics include rebalance-related measurements such as rebalance rate, total rebalances, and rebalance latency.

Application logs should also capture partition assignment and revocation events.

For example:

Java
@Override
public void onPartitionsRevoked(
    Collection<TopicPartition> partitions) {

    logger.info(
        "Partitions revoked: {}",
        partitions
    );
}

Use these logs to correlate rebalance events with:

  • Container restarts.

  • Deployment activity.

  • Garbage collection pauses.

  • Slow database queries.

  • External API timeouts.

  • Consumer lag increases.

  • CPU and memory pressure.

A high rebalance rate should be investigated rather than treated as a normal performance condition.

Common Mistakes That Increase Kafka Rebalancing

Mistake

Why it causes problems

Better approach

Processing large batches sequentially

The next poll() may occur too late

Adjust batch size and processing design

Increasing max.poll.interval.ms without investigation

Hides slow processing rather than fixing it

Measure processing duration first

Using unstable consumer identities

Restarts can repeatedly change group membership

Consider static membership where appropriate

Using a very short session timeout

Temporary interruptions can remove consumers

Choose timeouts based on actual infrastructure behavior

Scaling beyond the number of partitions

Additional consumers remain idle

Plan partition and consumer capacity together

Using eager rebalancing unnecessarily

More partitions may be revoked than required

Evaluate cooperative rebalancing

Performing expensive work in rebalance callbacks

Delays partition coordination

Keep callbacks short

Committing offsets before processing completes

Can cause message loss after failure

Commit only completed work

Ignoring consumer logs

Rebalance causes remain unclear

Correlate logs and metrics

Changing protocols without compatibility testing

Consumers may fail to join the group

Validate broker and client support first

A reliable Kafka consumer architecture should reduce unnecessary membership changes while ensuring that failed consumers can still be detected.

Consider the following practices:

  • Use a suitable partition count for the expected consumer workload.

  • Keep consumer instances stable where possible.

  • Use static membership when deployment and infrastructure patterns support stable identities.

  • Evaluate CooperativeStickyAssignor for classic consumer groups.

  • Consider the new consumer protocol when the broker and client versions support it.

  • Monitor poll intervals and message processing duration.

  • Keep expensive database and external API operations from blocking the polling loop indefinitely.

  • Use bounded processing queues rather than unlimited background tasks.

  • Commit offsets only after processing succeeds.

  • Keep rebalance callbacks short.

  • Use controlled deployment strategies to avoid unnecessary consumer churn.

  • Monitor rebalance frequency, latency, and consumer lag together.

The right configuration depends on the application's throughput, processing time, partition count, deployment model, and failure-recovery requirements.

Conclusion

Kafka consumer rebalancing is essential for distributing partitions across consumer instances and maintaining reliable group membership.

However, frequent rebalances can interrupt processing, increase consumer lag, and reduce application throughput.

Common causes include consumer restarts, failed heartbeats, long-running message processing, missed poll intervals, subscription changes, and partition updates.

Start by identifying why the group is rebalancing. Review consumer logs, poll intervals, session timeouts, processing duration, and group membership changes.

For classic consumer groups, cooperative rebalancing and static membership can reduce unnecessary partition movement and membership churn. For supported Kafka 4.x environments, the newer consumer rebalance protocol offers a fully incremental coordination model.

Most importantly, do not treat rebalancing as only a configuration problem. Design the consumer processing loop, offset management, deployment strategy, and monitoring together.

A stable Kafka consumer group should be able to handle scaling and failures without repeatedly interrupting normal message processing.