Configure the Amazon SQS visibility timeout: reduce redelivery and duplicate work
The Amazon SQS visibility timeout is the period during which a received message is hidden from other consumers. If a consumer does not finish processing and delete the message before the timeout expires, SQS can deliver it again. Set the timeout using observed processing time; for variable-duration work, combine in-progress extensions with idempotent processing.
The Amazon SQS visibility timeout is the period during which a received message is hidden from other consumers. If a consumer does not finish processing and delete the message before the timeout expires, SQS can deliver it again. Set the timeout using observed processing time; for variable-duration work, combine in-progress extensions with idempotent processing.
This guide covers Amazon SQS standard and FIFO queues only. Other brokers may define acknowledgements or locks differently.
Choose a queue default
The timeout starts when a message is received. The default is 30 seconds and can be changed in the queue configuration. The message remains in SQS but is hidden during that interval. Delete a successfully processed message with DeleteMessage to prevent another delivery.
Do not choose a value from the average processing time alone. Measure from receive through processing and deletion. For short, predictable work, start with a value that leaves reasonable headroom. If duration varies, use a practical default and extend only messages that need more time instead of setting every message to the longest possible duration. A value that is too short can expose work that is still running; a value that is too long delays retries after failure.
Extend long-running messages
If processing may exceed the default, use ChangeMessageVisibility to change that message's timeout. A worker can periodically send a heartbeat and extend the timeout before the current interval is close to expiring. Leave room for service latency and transient API failures. If an extension fails, continuing without a safe stop or duplicate protection can let another consumer start the same work.
An individual-message setting does not change the queue default. It applies to that receive; if the message is received again without being deleted, the queue's default applies. ChangeMessageVisibility requires the receipt handle for the current receive, and an old or invalid handle may fail.
For SQS, the timeout is limited to 12 hours from the first receive; extending it does not restart that limit. If work could exceed 12 hours, split it into stages or consider orchestration such as AWS Step Functions instead of holding one message for the entire job.
Plan for failure and redelivery
If a message is not deleted before the timeout expires, it becomes visible again and may be received by the same or another consumer. Standard queues use at-least-once delivery, so duplicates can occur even before the timeout expires. In FIFO queues, later messages in the same message group wait until an in-flight message is deleted or becomes visible again; a delayed message can therefore slow that group.
The visibility timeout is not a lock that guarantees exactly-once processing. Make side effects such as database updates safe to repeat by recording a message ID or business key. For difficult-to-reverse effects such as payments or email, use the external service's idempotency key or another deduplication mechanism.
Consider routing repeatedly failing messages to a dead-letter queue (DLQ) for diagnosis and controlled redrive. A DLQ helps isolate failures, but redriving without fixing the cause can repeat the failure.
| Symptom | Possible cause | Check and response |
|---|---|---|
| The same work overlaps | Timeout is shorter than processing, or extension failed | Record duration, receive time, and extension outcome; make handling idempotent |
| Failed work reappears very late | Queue default is too long | Review failure visibility and retry policy together |
| A job approaches 12 hours | One message holds a long job | Split the job or use orchestration |
| Later FIFO group messages stop | An earlier message is still in flight or not deleted | Check its processing state, timeout, and per-group throughput |
Verify the configuration
In a test queue, set a deliberately short timeout. Receive a message without deleting it and confirm it becomes available again after expiry. Then extend it with ChangeMessageVisibility, confirm it stays hidden for the extended interval, and delete it to confirm it is not redelivered. In production, monitor processing-duration distributions, extension successes and failures, redelivery, DLQ arrivals, and in-flight message counts. Because standard queues can duplicate messages during processing, verify business outcomes as well as timeout behavior.
Sources and scope
Amazon SQS Developer Guide, “Amazon SQS visibility timeout”: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html
Amazon SQS API Reference, “ChangeMessageVisibility”: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ChangeMessageVisibility.html
The 30-second default, 0–43,200-second per-message range, 12-hour limit from first receive, at-least-once behavior, and FIFO group behavior are specific to Amazon SQS and follow the cited AWS documentation.