Amazon SQS

Message Lifecycle & Visibility Timeout

Understand how a message is hidden during processing and returned if the consumer fails.

SQS does not push messages or hold per-consumer acks like RabbitMQ. Instead, a consumer polls and receives a message, which the queue then hides from other consumers for the visibility timeout. The consumer processes the message and, on success, explicitly deletes it. If it does not delete within the timeout (because it crashed or was slow), the message becomes visible again and another consumer picks it up — this is how SQS achieves at-least-once delivery.

A library reservation shelf: when you take a book to read (receive), it is marked "on hold" so no one else takes it (visibility timeout). If you check it out (delete) it is yours; if you wander off and the hold expires, it goes back on the shelf for the next person.

Key Concepts

1
Choosing the visibility timeout is critical: too short and a slow-but-healthy consumer's message reappears and gets processed twice; too long and a genuinely failed message takes ages to retry. A consumer that needs more time can extend the timeout dynamically with ChangeMessageVisibility (a heartbeat).
2
Because failed messages reappear, SQS consumers must be idempotent, and repeatedly failing messages should be routed to a dead-letter queue.