Kafka Transactional IdDistributed Systems & Databases
Task prompt
# Kafka Exactly-Once Payment Duplication A Kafka-based payment processing pipeline, deployed as a replicated Kubernetes workload, has started producing duplicate records in the downstream accounting database after a Kubernetes migration. - Duplication rate: ~0.02% (about 200 duplicates per million payments) - Started three weeks ago, coinciding with a Kubernetes migration - Pipeline ran correctly for six months before the migration - Kafka broker logs are clean - Producer EOS configuration appears correct Fix the pipeline so that a 1-hour production run at 10,000 messages/second with pod restarts every 60 seconds produces zero duplicate payment records in the accounting database while maintaining throughput >= 9,500 msg/sec. Do not change the following exactly-once semantics configuration: - Producer: `enable.idempotence=true`, `acks=all` - Consumer: `isolation.level=read_committed` Do not mask the problem with additional deduplication or duplicate suppression layers. The duplicates must be prevented at the source. Your `fixed_producer.py` artifact will be evaluated as a standalone Python file; it must not depend on other files under `/app`. Write the following artifacts to `/logs/artifacts/`: 1. `fixed_producer.py` — the corrected, self-contained producer 2. `consumer.py` — a copy of the unchanged consumer 3. `simulation_result.json` — result of running `/app/simulation.py` against `fixed_producer.py` 4. `root_cause.txt` — a brief explanation of the root cause and the fix