Visibility Timeout, Polling & Retention

How a message moves through a queue, and why it doesn't get processed twice at once.

1 min read

A message's life

  1. Send: the producer calls SendMessage.
  2. Receive: a consumer calls ReceiveMessage. The message becomes invisible to other consumers for the visibility timeout (30 seconds by default).
  3. Delete: after successful processing, the consumer calls DeleteMessage. Done.
  4. Didn't delete in time? The message becomes visible again and another consumer can retry it.
Watch out

Set the visibility timeout longer than your processing time. If processing takes 60 seconds but the timeout is 30, another consumer will pick up the same message while the first is still working on it.

Other key settings

SettingMeaning
Retention periodHow long unprocessed messages are kept: 4 days by default, up to 14 days
Long polling (WaitTimeSeconds up to 20)ReceiveMessage waits for messages instead of returning empty right away, which means fewer empty, billed calls
Delay queuesHide new messages for up to 15 minutes before they can be received
Message sizeMessages are limited in size, so put large data in S3 and send its key
How it flows
  1. 1SendMessage

    Message in queue

  2. 2ReceiveMessage

    Hidden for visibility timeout

  3. 3Process

    Your code does the work

  4. 4DeleteMessage

    Gone for good

Key takeaways

  • Received messages are hidden for the visibility timeout, then reappear if not deleted.
  • Always delete messages after successful processing.
  • Use long polling, and store large payloads in S3.

Check your understanding

Pick an answer to see the explanation.

  1. 1. Processing takes ~2 minutes, but messages are being handled twice. What's the likely cause?