SQS Visibility Timeout 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

preguntada hace 2 meses244 visualizaciones
1 Respuesta

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
respondido hace 2 meses
profile picture
revisado hace 2 meses
  • 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.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas