1

I had a question regarding SQS services.

If you have a SQS queue with multiple consumers and long polling enabled for FIFO type SQS. Which consumer gets preference for the delivery? Is it based on which started the polling first or is random? And also are there any good readings for this?

Thanks in advance!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470

1 Answers1

1

The number of consumers does not impact operation of the Amazon SQS queue. When a consumer requests messages from a FIFO queue, they will be given the earliest unprocessed message(s).

There is an additional Message Group ID on each message. While a message with a particular Message Group ID is being processed, no further messages with the same Message Group ID will be provided. This ensures that those messages are processed in-order.

Long-polling simply means that if no messages are available, then SQS will wait up to 20 seconds before returning an empty response. Long Polling is a default value that you can override with each request to the queue.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Just wanted to confirm that the consumer that polled first would receive the earliest unprocessed message ? – Shafeel Mohammed Dec 14 '21 at 21:44
  • 1
    Yes-ish. From [FIFO delivery logic - Amazon Simple Queue Service](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues-understanding-logic.html): "When receiving messages from a FIFO queue with multiple message group IDs, Amazon SQS first attempts to return as many messages with the same message group ID as possible. This allows other consumers to process messages with a different message group ID." So, it might receive several messages with the same Message Group ID, some of which are 'newer' than a message on the queue with a different Message Group ID. – John Rotenstein Dec 14 '21 at 22:14
  • Thanks for the clarification that helps a lot! – Shafeel Mohammed Dec 15 '21 at 00:19