Home > Net >  Understanding lambda concurrency
Understanding lambda concurrency

Time:08-11

I am trying to understand how a lambda triggered by SQS fifo queue handles load and concurrency.

To test, I've created a lambda that publishes X number of messages to an SQS fifo queue (single MessageGroupId). FIFO queue has a batch size 1.

The lambda that is invoked from the SQS FIFO trigger has a sleep of 5 seconds to incur message build up on the queue.

If I publish 100 messages onto the queue, how does lambda handle the load? Each invocation can only receive one message because of batch size 1. In my testing, the total processing time is still 100 * 5 seconds so everything is executed in order.

My understanding is that a lambda is supposed to "scale up" and requests can be processed in parallel, so I assumed that it should process concurrently. But I guess this doesn't work with FIFO queue.

Will my lambda only scale up if I send messages with different MessageGroupIds? Can I safely assume, no matter the duration of my lambda, each request will be processed in order?

CodePudding user response:

You are correct.

If a message with a particular MessageGroupId is "in flight" (being processed by an AWS Lambda function), then no other message with the same MessageGroupId will be given to Lambda. This ensures that messages are processed in-order.

A few options:

  • Increase the batch-size so that the Lambda function receives multiple messages (which can be the same MessageGroupID)
  • Use different MessageGroupId where possible, so that they can be processed in parallel
  • Related