I am working on a usecase where we have multiple events incoming from up streams and it is possible that we will have multiple events for 1 employee. But we want to make sure that there is only 1 active process is there for 1 employee and we want to delay processing of other events with same employeeID but events for different employees can process. While doing this we still want to maintain the order of events for an employee.
I was thinking of below approach
FIFO SQS → Lambda - In this scenerio we can use a lock on basis of employee(maybe in dynamoDB) and lambda can requeue event if there is an active lock on that employee. But I am not sure how we can maintain order here? If we requeue events in FIFO won't new events get processed first before requeued events?
It is simpler than that.
Simply use an Amazon SQS FIFO queue and specify the Employee ID in the
MessageGroupId.From Using the Amazon SQS message group ID - Amazon Simple Queue Service:
If the batch size is greater than 1, then it is possible to retrieve multiple messages with the same MessageGroupId in a single
ReceiveMessages()call, but they will be in order. If the batch size is 1, then only one consumer will be given a message for a given MessageGroupId.