I need to process status changes related to an entity in a sequential order. Not in parallel.
Will an SQS FIFO Group with MessageGroupId = UserId be enough?
Let's say I have the folowing messages:
- MessageGroupId = 1, status: :pending
- MessageGroupId = 2, status: :pending
- MessageGroupId = 1, status: :approved
And I have 10 consumers of that FIFO Queue.
Will 1 consumer process in sequence:
- MessageGroupId = 1, status: :pending
- MessageGroupId = 1, status: :approved
Or can it happen that both messages are processed, in parallel - but in order -, by different consumers?
1 Answer 1
Messages are processed in the order they are received (First In First Out). Up to 10 messages can be received at once, if there are less than 10 messages with the same group ID, one can receive messages for another message group ID, but the FIFO order is maintained.
One should set the visibility time out to a value that corresponds to a time that the message takes to process. This effectively hides the message for other consumers. The default value is 30 seconds. This will reduce the chance of duplicate messages if set properly on standard queue.
Also, all queue processing should be idempotent, to account for duplicate messages because all that is guaranteed is "at least once delivery". This applies for standard queues.
For FIFO queues, there are measures in place to have exactly-once processing that one should be aware of.