SQS Visibility Timeout 0

0

I have an SQS queue with visibility timeout 0 to test how it works because I intend to use that setting for something that is outside of scope of this explanation. I have a Lambda function triggered by that queue with concurrency limit 1, i.e. only 1 function can run at any given time. In the function I read the messages from the queue using the API and immediately delete the received message. If I send 1 message into the queue, it is repeatedly received, even long after it was deleted from the queue. Why does the message keep being received several seconds after it was deleted?

  • please accept the answer if it was useful

asked a year ago868 views
1 Answer
1

The visibility timeout is the period of time during which a message is invisible to other consumers after it has been read from the queue. Setting the visibility timeout to 0 means the message is immediately visible to other consumers again.

When a Lambda function is triggered by an SQS queue, it reads messages and attempts to process them. If the visibility timeout is set to 0, the message becomes available for other consumers (or the same consumer) immediately after it is read, leading to potential reprocessing of the same message before the deletion request is processed.

There might be a slight delay between when the Lambda function deletes the message and when the deletion is acknowledged by SQS. During this period, the message can be reprocessed by the Lambda function because it is still visible.

Setting the visibility timeout to 0 causes messages to be immediately visible to other consumers, leading to repeated processing. Increase the visibility timeout to a value greater than 0 to ensure messages are not reprocessed before they are deleted. Ensure proper deletion logic in your Lambda function to handle messages efficiently.

profile picture
EXPERT
answered a year ago
profile picture
EXPERT
reviewed a year ago
  • To sum up, setting the visibility timeout to 0 is generally not recommended as it can lead to repeated message processing. A higher visibility timeout value helps ensure that messages are processed and deleted properly, avoiding unnecessary reprocessing.

  • The problem is that there is not "a slight delay". The message keeps being received for the whole lifetime of the message, i.e. 1 minute in my case, despite being deleted. So that is not a feature, that is a bug in my opinion.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions