0PricingLogin
AWS Solutions Architect · Lesson

Visibility Timeout, DLQ, and Long Polling

Set visibility timeouts so messages are not processed twice, route failed messages to a dead-letter queue, and reduce costs with long polling.

The Visibility Timeout Mechanism

When a consumer receives a message from SQS, the message is hidden from all other consumers for a period called the visibility timeout. During this window, the consumer processes the message and then deletes it. If the consumer crashes or doesn't finish in time, the visibility timeout expires and the message becomes visible again, allowing another consumer to pick it up. This is the core mechanism behind SQS's at-least-once delivery guarantee.

Configuring Visibility Timeout

The default visibility timeout is 30 seconds. It can be set from 0 seconds to 12 hours. Set it to comfortably exceed your maximum expected processing time—if processing takes up to 2 minutes, set the timeout to at least 3-4 minutes. You can also change the timeout per-receipt using change-message-visibility, which is useful when a consumer detects it needs more time to finish processing a specific message.

# Extend visibility timeout for a specific message
aws sqs change-message-visibility \
  --queue-url 'https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue' \
  --receipt-handle 'AQEBwJnKyrHigUMZj...' \
  --visibility-timeout 300

All lessons in this course

  1. SQS Standard vs FIFO Queues
  2. Visibility Timeout, DLQ, and Long Polling
  3. SNS Topics and Fan-Out Architecture
  4. SQS Message Filtering and SNS + SQS Integration
← Back to AWS Solutions Architect