Home > Blockchain >  Understand SQS visibility timeout with multiple pollers
Understand SQS visibility timeout with multiple pollers

Time:12-13

I've read in multiple places that sqs use of minimum 5 pollers simultaneously to pull messages from queue. So if there's aren't sufficient available consumers (I'm using lambdas), then a message will be throttled and get back to the queue. And It's therefor recommended to set visibility timeout 6 times of the process time (Or lambda timeout). The thing that i fail to understand - When there's polling of a message from the queue without available consumer - During that visibilityTimeout window will the message still be assigned to a consumer that gets available? Or once throttled it gets back to the queue right away. I just fail to understand the entire logic behind visibilityTimeout configuration had would appreciate explanation in this matter. If I need that a message that was pulled from queue but no availble consumer to take it at the moment- How can i set it to be back to be picked straight away? This is not a Fifo queue. Thanks

I can see i have throttled messages and not sure if im configured properly (Im with concurrency of 12, lambda timeout set to 60 and visibilityTimeout also 60 right now)

CodePudding user response:

The lambda service gets the message(s) from the queue and then tries to invoke a lambda function with that message. There are couple of things that can happen:

  • lambda accepts the message, processes it and succeeds -> lambda service attempts to delete message from queue
  • lambda accepts the message, fails to process it -> lambda service discards the message, after the visibility timeout expires the message becomes visible again, no retries by the lambda service in this case.
  • lambda rejects the message due to throttling -> lambda service will retry the message after "lambda timeout" seconds, up to 5 such retry attempts happen

Because you cannot know if your lambda will ever be throttled you must assume it will be throttled, therefore you must ensure that even the 5 retires and a potential execution in the last retry all happen within the configured visibility timeout: therefore visibility timeout = 6 * lambda timeout.

If you incorrectly configure the visibility timeout the message might become visible while the lambda (service) is already / still working on it leading to multiple executions of the same message.

  • Related