skip to content

A payments team on a 3.9 cluster upgraded to Kafka 4.x rolls 60 consumers to group.protocol=consumer one pod at a time; how does the online conversion work, and what can block it?

level: seniorimportance: should knowfreq 35%

answer

  1. finalize the broker upgrade first
  2. first new member flips the group
  3. old pods keep JoinGroup and SyncGroup
  4. custom assignor metadata blocks it
  5. last new member leaving flips back

basics

~20 s

The first consumer-protocol pod's heartbeat converts the classic group; the remaining classic pods are served through JoinGroup and SyncGroup. Conversion is refused if the migration policy forbids it, the group exceeds group.consumer.max.size, or a custom assignor embeds metadata.

solid answer

~40 s

First the cluster upgrade to 4.x must be finalized, which enables the consumer protocol through `group.version`. When the first pod with `group.protocol=consumer` sends `ConsumerGroupHeartbeat`, the coordinator converts the non-empty classic group into a consumer group: it computes assignments with the server-side assignor, and the 59 classic pods keep using JoinGroup, SyncGroup and Heartbeat, getting `REBALANCE_IN_PROGRESS` when they need to rejoin and receiving their share of the coordinator's assignment. The conversion is refused if `group.consumer.migration.policy` disables upgrades (default `bidirectional`), if the group is not a plain `KafkaConsumer` group, if it exceeds `group.consumer.max.size`, or if the classic assignor embeds custom user data. New pods must also drop `partition.assignment.strategy`, `session.timeout.ms` and `heartbeat.interval.ms`, or they crash at startup. Rolling back reverses it: the group turns classic again when the last consumer-protocol member leaves.

code

bash · 5 lines
bash
# Is the 4.x upgrade finalized? Look for group.version with FinalizedVersionLevel 1
bin/kafka-features.sh --bootstrap-server broker1:9092 describe

# After the first pod rolls: has the group become a consumer-protocol group?
bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --list --type classic,consumer

go deeper

for a junior

Remember that a group can switch protocols during a rolling deploy: the first new pod converts it, and old pods keep working until they are restarted.

for a middle

Know the preparation: finalize the 4.x broker upgrade, remove the rejected client configs, and map the old assignor to group.remote.assignor if its behaviour matters.

for a senior

Diagnose a blocked roll from the coordinator log: migration policy, embedded protocol, group size or custom assignor data, and know that rollback converts the group back when the last new member leaves.

for a principal

Treat group.consumer.migration.policy as a fleet guardrail, and plan for the one-way cluster downgrade limit once groups use the new protocol.

## The starting point The scenario: a payments service runs 60 instances of a `KafkaConsumer` in one consumer group. The cluster was on 3.9 and has been upgraded to 4.x; now the team changes the consumer config to `group.protocol=consumer` (Kafka 4.0's KIP-848 consumer group protocol) and rolls the deployment one pod at a time, without stopping consumption. Two preconditions decide whether that can work at all: - **The broker upgrade must be finalized.** The Kafka upgrade notes say the new protocol is enabled automatically on the server when the upgrade to 4.0 is finalized; it is governed by the `group.version` feature, which `kafka-features.sh describe` shows. Note the one-way door: once groups use the new protocol, the cluster can only be downgraded to 3.4.1 or newer. - **The new pods' config must be valid.** With `group.protocol=consumer`, the `KafkaConsumer` constructor throws a `ConfigException` if `partition.assignment.strategy`, `session.timeout.ms` or `heartbeat.interval.ms` is set. A shared properties file that still carries them turns a rolling deploy into a crash loop on the first pod. ## What happens when the first new pod joins 1. The new pod sends `ConsumerGroupHeartbeat` with member epoch 0 to the group's coordinator. 2. The coordinator finds a non-empty **classic** group with that id and validates an **online upgrade**. 3. If validation passes, it converts the group: it writes a consumer-group record set in place of the classic group, bumps the group epoch and computes a target assignment with the server-side assignor. 4. Any classic JoinGroup or SyncGroup in flight is answered with `REBALANCE_IN_PROGRESS`, so the old pods rejoin into the converted group. From then on the group is a **mixed** consumer group. The 59 classic pods still speak JoinGroup, SyncGroup and Heartbeat; the coordinator translates. A classic member's heartbeat gets `REBALANCE_IN_PROGRESS` when its epoch is behind the group epoch, when it must revoke partitions, or when partitions it is waiting for have become free. It then rejoins and receives, through SyncGroup, the assignment the **coordinator** computed. Its own `partition.assignment.strategy` no longer decides the plan, although its client still behaves as it always did while rejoining: a classic member on an eager assignor revokes everything it owns before it rejoins, so the mixed phase is not free for such pods. ## What can block the conversion The coordinator refuses the upgrade, logs "Cannot upgrade classic group ... to consumer group because ...", and returns an error to the new pod in these cases: | Condition | Source of the rule | |---|---| | `group.consumer.migration.policy` does not allow upgrades (`downgrade` or `disabled`; the default is `bidirectional`) | broker config | | the classic group does not use the consumer embedded protocol, i.e. it is not a plain `KafkaConsumer` group | group type check | | the group has more members than `group.consumer.max.size` | broker config, unlimited by default | | the classic assignment carries custom user data from a custom assignor | the conversion would lose that data | The last one is the condition the Kafka docs state as "only possible when the classic group uses an assignor that does not embed custom metadata". The built-in assignors are covered by the documented mapping: `RangeAssignor` to `range`; `RoundRobinAssignor`, `StickyAssignor` and `CooperativeStickyAssignor` to `uniform`. If the team relies on `RangeAssignor`'s co-partitioning, the new pods should set `group.remote.assignor=range`; otherwise the coordinator uses the first entry of `group.consumer.assignors`, which is `uniform` by default. ## Watching it, and rolling back - `kafka-consumer-groups.sh --list --type classic,consumer` shows whether the group's TYPE is now `Consumer` rather than `Classic`. - Expect the group epoch to rise with every pod restart; each restart is a leave plus a join. - **Rollback** is the same roll in reverse. With the default `bidirectional` policy, the group converts back from consumer to classic when the **last** consumer-protocol member leaves. - **Offline alternative**: stop all 60 pods and start them with the new config. Empty groups convert in either direction regardless of the migration policy, at the cost of downtime. ## Checklist for the payments team 1. Confirm the 4.x upgrade is finalized and `group.version` is enabled. 2. Strip the three rejected configs from the new image and set `group.remote.assignor` if needed. 3. Check the broker's migration policy and maximum group size. 4. Roll one pod, confirm the group type and that partitions keep flowing, then continue.

  • Halfway through the roll the team must revert. What happens to the group?
    They roll the pods back to `group.protocol=classic`. While any consumer-protocol member remains, the group stays a mixed consumer group. When the last one leaves, the coordinator converts it back to a classic group, provided `group.consumer.migration.policy` allows downgrades, which the default `bidirectional` does.
  • The first new pod logs an error and never joins, while the old pods keep consuming. Where do you look first?
    At the coordinator broker's log for "Cannot upgrade classic group". Its reason names the cause: online upgrade disabled by the migration policy, the group not using the consumer embedded protocol, the size limit, or an unsupported custom assignor. If the pod crashed instead, check its config for the three keys the consumer protocol rejects.

  • Online migration needs every pod stopped first so the group can be empty
  • Classic and consumer-protocol pods cannot coexist in one group during a roll
  • Any assignor blocks conversion, so you must first switch to CooperativeStickyAssignor
  • Once converted, a group can never return to the classic protocol
  • Old partition.assignment.strategy settings are harmless on the new pods

Assumes brokers on Kafka 4.0 or later with the upgrade finalized; online classic-to-consumer conversion and group.consumer.migration.policy checked against the 4.3.1 source.