AWS › Amazon SQS (Simple Queue Service)

What is visibility timeout in SQS, and why is it important for reliable message processing?

Intermediate

Answer

Visibility timeout is the period of time after a consumer retrieves a message during which that message becomes temporarily invisible to other consumers, giving the original consumer time to process and delete it, and if the consumer fails to delete the message before the visibility timeout expires, the message automatically becomes visible again so another consumer can retry processing it, preventing lost messages due to a crashed worker.
aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/OrderQueue --attributes VisibilityTimeout=60
Real-world example A payment processing worker sets its queue's visibility timeout to sixty seconds, matching the expected time needed to process a payment, so if a worker crashes mid processing, another worker automatically picks up the same message after that timeout expires.

Common follow-ups: What happens if the visibility timeout is set too short for the actual processing time?;How do you extend the visibility timeout for a message still being processed?