fix: add Kafka static membership to stop rebalance storm#75
Merged
Conversation
0.3.14 removed the close+recreate on ILLEGAL_GENERATION on the assumption librdkafka would auto-rejoin on the next consume(). It doesn't — commits kept failing indefinitely in production. This restores the 0.3.13 recreate-in-place behavior AND adds static membership (KIP-345) via HOSTNAME (K8s pod name). With a stable group.instance.id the reconnecting consumer is recognized as the same instance, so the close+recreate no longer triggers a full-group rebalance that cascades to invalidate all other consumers' commits. Users can override by setting group.instance.id in consumer_config. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
commit()(0.3.14's "just log and return" was wrong — librdkafka didn't auto-rejoin and commits kept failing indefinitely in production)group.instance.idauto-derived from the K8s-injectedHOSTNAMEenv var. With a stable instance ID, the close+recreate reconnects as the same member, so the broker skips the full-group rebalancegroup.instance.idexplicitly inconsumer_configWhy this fixes the storm
Inspecting the consumer group via
AdminClient.describe_consumer_groupswhile the storm was live:Each pod's
consumer.close()sentLeaveGroup, and each newConsumer()joined as a brand-new dynamic member (differentmember.id). With 16 pods recreating every ~40s andsession.timeout.ms=60s, the group accumulated ghosts and stayed permanently inPREPARING_REBALANCING. Cooperative-sticky made each rebalance incremental but couldn't eliminate them — adding/removing group members always triggers one.With static membership, the recreate reconnects to the existing slot → no
LeaveGroup-driven rebalance → no cascade.Preemptible node interaction
Test plan
uv run pytest tests/connectors/sources/kafka/— 27 tests passuv run ruff check && formatKafka static membership enabled: group.instance.id=...AdminClientdescribe showsgroup_instance_idpopulated on the memberconversations-events(16 replicas). Verify:memberscount in the group equals live pod count (no ghost accumulation)Recreating consumerlog frequency drops dramatically (may still appear occasionally for legitimate rebalances, but not cascading)Rollback
Single revert. Recreate logic is already there (from 0.3.13), static membership is purely additive.
🤖 Generated with Claude Code