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.

    • 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).

      • 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.

      • The default visibility timeout for a message is 30 seconds.

Setting the visibility timeout

  • The visibility timeout begins when SQS returns a message.

    • During this time, the consumer processes and deletes the message.

      • 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.

Last updated