A message broker guarantees at-least-once delivery. What must consumers do?
Options
- Nothing, since each message arrives only once
- Be idempotent: dedupe by ID or repeat safely (Correct option)
- Always switch the broker to exactly-once mode
- Acknowledge the message before processing it
Answer
Be idempotent (deduplicate by message ID or make operations naturally repeatable)
Why
'At-least-once' means a message is never lost, but it may arrive twice. For example, the consumer processed it but crashed before confirming, so the broker sends it again.
So processing the same message twice must be harmless: store processed message IDs and skip repeats, or use operations like 'set status = paid' instead of 'add 10 €'.
Confirming before processing would risk losing messages instead.
Remember
At-least-once delivery → idempotent consumers.