intermediatePersistence Layer

Why does a Kafka consumer that writes to a database need to think about idempotency, not just 'save the record'?

Kafka's at-least-once delivery (the default, safest guarantee without extra work) means the SAME message can be delivered and processed more than once, e.g. after a consumer restart before it committed its offset. Without an idempotency check (like a unique constraint on an event ID, or an upsert instead of a blind insert), a redelivered message can create duplicate rows or double-apply an effect.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why might a consumer intentionally write to a local database inside the SAME transaction as committing its Kafka offset?← Back to all Kafka & Microservices questions