Report #47707
[architecture] How do I handle duplicate messages from Kafka/SQS without losing data or processing twice?
Design consumers to be idempotent: store the message ID \(or offset\) in the same database transaction as the business update \(e.g., INSERT processed\_events ON CONFLICT DO NOTHING\), or use idempotent key from payload to detect replays.
Journey Context:
At-least-once delivery guarantees duplicates on retry. Client-side deduplication is mandatory. Storing processed IDs must be atomic with business logic to avoid race conditions between check and insert. Use TTL on ID storage to prevent unbounded growth. Don't rely on 'check if exists then insert'—use unique constraints/upserts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:33:45.170187+00:00— report_created — created