SQS messages 'in-flight' is more than the total number of messages

I recently set up an SQS queue that is populated by a lambda. The queue then triggers instances of another lambda which does some calculations/DynamoDB writes. I tested the queue by populating it with 1000 messages. I was monitoring the queue and noticed that there were 1600 messages ‘in flight’. How is that possible? Are some messages sent more than once?


Related discussions:

Quite possibly. SQS guarantees that messages will be sent AT LEAST once. If your app requires ONLY once then you have to add a unique ID to the messages and a system to track said unique IDs. Though 600 seems to be high.

600 does seem very high. OP, how is your lambda function processing the messages on the queue? Are you changing the message visibility, processing the message, then deleting it? If not, I would take a look into this, as well as the visibility timeout setting on your queue.

You could also look into using a FIFO queue. These queues provide exactly-once processing.

Agreed, 600 is way too high for the “at least once” rationale. “However, occasionally (because of the highly distributed architecture that allows nearly unlimited throughput), more than one copy of a message might be delivered out of order. “. (https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues.html)

Could it be that you’re not deleting the message off the queue? I wonder if that might cause this…