Skip to content
RED SAGSkills
hardBackend Developer interview question

A product manager says each payment event must be processed exactly once. How do you achieve that with real message queues and networks?

What the interviewer wants to hear

  • Exactly-once delivery is not possible across networks in general
  • Use at-least-once delivery plus idempotent processing for effectively-once
  • Deduplication with unique keys or processed-event table in the same transaction
  • Transactional outbox and Kafka transactions where useful
  • Handle ordering, retries and poison messages

Model answer

Over an unreliable network you cannot guarantee a message is delivered exactly once: if an acknowledgement is lost, the sender must choose between retrying, which risks duplicates, or not, which risks loss. So we aim for effectively-once: at-least-once delivery combined with idempotent processing. Each event carries a unique id. The consumer, in the same database transaction as its business change, inserts that id into a processed_events table with a unique constraint; a duplicate fails the insert and is skipped. On the producer side, the transactional outbox ensures the event is published if and only if the business data was committed. Kafka offers idempotent producers and transactions for read-process-write inside Kafka, but side effects in external systems still need idempotency keys, for example when calling the payment provider. I also plan for ordering per key, retries and a dead-letter queue.

Can you answer it under time pressure?

Take a timed hard round and get scored on every answer.

Start mock interview

More hard Backend Developer questions