Reputation: 766
I’m currently building a system that requires messages sent into a FIFO SQS queue to be processed in order. I’ve considered configuring lambda functions to process the data, but I’m running into a race condition. If lambda 1 begins processing 100 messages, and immediately after lambda 2 starts processing 5 messages, lambda 2 will likely finish first.
How do I ensure that lambda 1 will always process its messages before lambda 2? Thank you!
Upvotes: 2
Views: 739
Reputation: 2943
If you do not have a lot of load (subjective to your use case), you can use a single threaded system to solve this. Lambda inherently launches multiple instances in parallel based on demand and is probably not suitable for your use case.
As pointed in comments, you may want to use a lock using Redis or DynamoDB to synchronize the execution, but this will result in a lot of issues and unnecessary overhead.
You are better off, using an EC2 instance and poll the SQS FIFO queue.
Upvotes: 1