Messaging patterns · mid
Where duplicates and losses really come from
Every queue promises at-least-once delivery at best. A message can be lost or duplicated at the producer, the broker and the consumer. The defence is idempotent consumers plus checks that find losses.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Producer, lost: a dual write (commit, then crash before publishing), fire-and-forget publishing with no acks or confirms, a failed send that is only logged. Producer, duplicated: a retry after a lost acknowledgement, a client that retried an API call, an outbox relay republishing after a crash.
- Broker, lost: weak replication (min.insync.replicas=1, unclean leader election, a classic non-replicated queue), retention or TTL deleting unread messages, length limits dropping messages, unroutable messages dropped.
- Consumer, lost: acknowledging or committing before the work is done. Consumer, duplicated: a crash after the work but before the ack or commit, a rebalance, a visibility or consumer timeout, a dropped connection, a dead-letter redrive.
- Side effects outside your database (email, payment, partner calls) cannot be rolled back with your transaction.
- The defence is at-least-once delivery with idempotent consumers: dedupe by event id in the same database transaction as the change, use naturally idempotent writes (upserts, conditional updates by version), and send idempotency keys on external calls. Add reconciliation jobs that compare source and destination to find losses.
- Exactly-once claims are narrow: Kafka's covers read-process-write inside Kafka, and SQS FIFO covers duplicate sends within 5 minutes. Neither covers your database or external calls.
The red pen
Common traps: mistake → fix
Mistake: Exactly-once is solved by the broker
Fix: only inside narrow limits.
Mistake: Duplicates come only from consumer crashes
Fix: list producer and broker causes too.
Mistake: We will notice a loss
Fix: without reconciliation, nobody does.
Easy to hard
Questions interviewers ask, easy to hard
- Every queue promises at-least-once. Where can a message be duplicated or lost?
- What is idempotency and how do you get it?
- Tell me about a messaging problem you debugged.
- Can you get exactly-once delivery?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.