Why can a message from a queue arrive a second time?
Answer out loud or in your head first, then compare.
Answer
The queue and the program doing the work don't always both know whether the job was completed. The program may have saved the result and then exited before acknowledging. The queue sees no acknowledgement and allows another attempt.
That's often a deliberate choice: better to allow a repeat than to lose a job. So handling has to be ready for duplicates. If a message says “add 10 to the counter”, without protection two deliveries add 20. You need a stable identifier of the same operation and a way to recognise that its effect has already been saved. The details of the guarantees depend on the queue used and its configuration.
Why it matters: The simplest way into the problem of queue reliability.
Possible follow-ups: Does acknowledging before doing the work solve the problem without new risks?
How did it go? Be honest — “Not yet” puts the question on your review list.
Practise in code
- Find the bugs in a queue consumer — guided self-review
Further reading
- AWS: Using Lambda with Amazon SQS(opens in a new tab)Docs; accessed 22.10.2026. Polling, batches, duplicates and partial batch responses.
- AWS: What is Amazon SQS?(opens in a new tab)Accessed 22.10.2026. Producer, queue, consumer and the message lifecycle.