Our orders enrichment consumer reprocesses ~4M messages every time we deploy. The team added enable_auto_commit=False and explicit commit() calls weeks ago, so this should have stopped. Run tests/test_offsets_persist.py to reproduce. The reprocess window correlates with rebalance events. Find why the explicit commits aren't sticking and fix it. Bonus credit: explain what 'cooperative-sticky' would have changed.
consumer/run.py
# consumer/run.py # Streaming consumer that enriches orders with user_country and writes # to the warehouse. Auto-commit was disabled weeks ago (see git blame on # this file) but offsets still don't survive a rebalance. from consumer.client import KafkaConsumer from consumer.warehouse import write_enriched from consumer.enrich import enrich BATCH_SIZE = 500 def run(consumer: KafkaConsumer, max_messages: int) -> int: processed = 0 batch = [] for msg in consumer: batch.append(msg) if len(batch) >= BATCH_SIZE: enriched = [enrich(m) for m in batch] write_enriched(enriched) consumer.commit() processed += len(batch) batch = [] if processed >= max_messages: break if batch: enriched = [enrich(m) for m in batch] write_enriched(enriched) consumer.commit() processed += len(batch) return processed
Active Now|Sr. (L5)|||3.4k Attempts|1.5k Solves|
A medium ai_coding interview practice problem on DataDriven. Write and execute real ai_coding code with instant grading.
- Domain
- ai_coding
- Difficulty
- medium
- Seniority
- L5
Problem
Our orders enrichment consumer reprocesses ~4M messages every time we deploy. The team added enable_auto_commit=False and explicit commit() calls weeks ago, so this should have stopped. Run tests/test_offsets_persist.py to reproduce. The reprocess window correlates with rebalance events. Find why the explicit commits aren't sticking and fix it. Bonus credit: explain what 'cooperative-sticky' would have changed.
Summary
It happened. It happened again.
Practice This Problem
Solve this ai_coding problem with real code execution. DataDriven runs your solution and grades it automatically.