fix: use stable Kafka warmup group ID and offset-aware catch-up (fixes #19)#21
Open
jishanahmed-shaikh wants to merge 1 commit into
Open
Conversation
Previously warmupKafkaCache() used a time-based consumer group ID (warmup-consumer-<timestamp>) on every startup. Because Kafka had no record of what was already processed, it always replayed every message from offset 0 across all topics. Startup time grew linearly and unboundedly with total message history. Changes: - Replace time-based groupId with stable 'ascent-warmup-stable' so Kafka tracks committed offsets across restarts. Only messages produced since the last startup are replayed on subsequent boots. - Fetch the high-water-mark (latest offset) for every partition via the Admin API before starting the consumer. Stop the consumer as soon as all partitions are caught up instead of relying on an arbitrary 1s sleep, which was both unreliable under load and wasteful on idle. - Exclude partitions with no messages (offset 0) so a fresh cluster skips warmup entirely. - Enable autoCommit so progress is durable and survives crashes mid-warmup. - Add per-step console logs so operators can observe warmup progress. Fixes: 11byte#19
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.
Problem (Closes #19)
The
warmupKafkaCache()function inbackend/src/utils/warmupKafka.tsused a time-based consumer group ID on every startup:groupId: `warmup-consumer-${Date.now()}`Because Kafka had no record of what this group had already processed, it always started from offset 0 and replayed every message ever produced.
Impact
Secondary Issue
The consumer stopped after an arbitrary 1-second delay:
This caused:
Root Cause
Two independent bugs:
1. Non-stable group ID
2. Arbitrary sleep as stop condition
Fix
1. Stable Consumer Group ID
Behavior
fromBeginning: true2. Offset-aware Catch-up using Admin API
Before starting the consumer, fetch the latest offsets (high-water mark) for each partition:
Inside
eachMessage, track catch-up:Key Improvements
Additional Notes
autoCommit: trueensures durability across restarts/crashesBehaviour Comparison
Files Changed
backend/src/utils/warmupKafka.ts- full rewrite of warmup logic