fix: prevent Kafka consumer rebalance during long BigQuery writes#66
Merged
Conversation
Overlap consume(N+1) with write(N) using a background thread so heartbeats stay alive during destination writes. Backpressure ensures at most 2 batches in memory. Also adds max.poll.interval.ms=600s default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
anaselmhamdi
added a commit
that referenced
this pull request
Apr 7, 2026
PR #66 (v0.3.8) wrapped destination writes in a ThreadPoolExecutor with the goal of overlapping consume(N+1) with write(N) to keep Kafka polls alive during long BigQuery writes. The implementation waits for pending_future.result() *before* calling source.get(), so consume always runs after the previous write finishes — no actual overlap, just thread overhead, a one-iteration commit delay, and a destination-object thread safety footgun. This restores the simple sequential loop. The max.poll.interval.ms=600000 Kafka consumer default introduced in 0.3.8 is intentionally retained as a safety net against rebalance during long writes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6 tasks
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
consume()with BigQuery writes using a single background thread, so the main thread keeps polling and heartbeats stay alive during long destination writesmax.poll.interval.ms=600000(10 min) to default Kafka consumer config as a safety netfuture.result()ensures at most 2 batches in memory (one writing, one being consumed)Context
With a single Kafka consumer handling multiple topics, BigQuery writes block the main thread. During writes, no
consume()calls happen, so no heartbeats are sent. Kafka evicts the consumer → rebalance → all topics stall reading 0 messages for minutes. Increasingmax.poll.interval.msalone just delays the stall; reducingbatch_sizekills throughput with few partitions.Test plan
future.result()re-raises🤖 Generated with Claude Code