> For the complete documentation index, see [llms.txt](https://karansingh.gitbook.io/aws-saa-c02/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://karansingh.gitbook.io/aws-saa-c02/simple-queue-service-sqs/message-visibility-timeout.md).

# Message Visibility Timeout

* When a consumer receives and processes a message from a queue, the message remains in the queue but it **becomes invisible to other consumers**.<br>
  * SQS doesn't automatically delete the message - Because Amazon SQS is a distributed system, **there's no guarantee that the consumer actually receives the message (for example, due to a connectivity issue, or due to an issue in the consumer application)**.<br>

    * **So, the consumer must delete the message** from the queue after receiving and processing it.

* Immediately after a message is received, it remains in the queue.
  * To prevent other consumers from processing the message again, Amazon SQS sets a visibility timeout, **a period of time during which SQS prevents other consumers from receiving and processing the message**.<br>
    * The default visibility timeout for a message is 30 seconds.

## Setting the visibility timeout

* The visibility timeout begins when SQS returns a message.<br>
  * **During this time, the consumer processes and deletes the message**.<br>

    * However, **if the consumer fails before deleting the message and your system doesn't call the `DeleteMessage` action for that message before the visibility timeout expires, the message becomes visible to other consumers** and the message is received again.

* **If a message must be received only once, your consumer should delete it within the duration of the visibility timeout**.
