# How does SQS know to wait for message 1 when message 2 arrives first for a group id?

**URL:** <https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774>\
**Category:** Billing & Cost\
**Tags:** sqs\
**Created:** [November 18, 2025, 3:20pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774 "2025-11-18T15:20:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avansay](https://awshq.com/letter_avatar_proxy/v4/letter/a/4bbf92/32.png) [@Avansay](https://awshq.com/u/Avansay)\
**Post date:** [November 18, 2025, 3:20pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/1 "2025-11-18T15:20:14Z")

</div>

i’ve spent way too much time with chatgpt trying to clarify this but dont get it. I might be being a bit slow here.

- i produce an purchase message with customer 444 as the group id, then
- i produce an invoice message with customer 444 as the group id

and the invoice comes before the purchase, how does sqs know to wait for the purchase message? chatgpt just keeps saying “oh sqs just knows the purchase is supposed to come first”

---

<div class="post-metadata">

**Author:** ![clintkev251](https://awshq.com/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@clintkev251](https://awshq.com/u/clintkev251)\
**Post date:** [November 18, 2025, 3:25pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/2 "2025-11-18T15:25:07Z")

</div>

Because it was first in. Really no more complex than that

---

<div class="post-metadata">

**Author:** ![CircularCircumstance](https://awshq.com/letter_avatar_proxy/v4/letter/c/f14d63/32.png) [@CircularCircumstance](https://awshq.com/u/CircularCircumstance)\
**Post date:** [November 18, 2025, 3:25pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/3 "2025-11-18T15:25:09Z")

</div>

SQS isn’t supposed to guarantee ordering, that’s up to the app side. It guarantees queueing.

---

<div class="post-metadata">

**Author:** ![Drumedor](https://awshq.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@Drumedor](https://awshq.com/u/Drumedor)\
**Post date:** [November 18, 2025, 3:28pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/4 "2025-11-18T15:28:39Z")

</div>

It doesn’t. The message group Id puts the messages into different lanes, and then it processes the messages within each lane in the order they arrived, so if you send the invoice message first, the invoice will be processed first.

---

<div class="post-metadata">

**Author:** ![Drumedor](https://awshq.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@Drumedor](https://awshq.com/u/Drumedor)\
**Post date:** [November 18, 2025, 3:29pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/5 "2025-11-18T15:29:14Z")

</div>

> [@CircularCircumstance](#):
>
> SQS isn’t supposed to guarantee ordering, that’s up to the app side. It guarantees queueing.

They are using message group Id which is only a thing for fifo queues, which do guarantee ordering.

---

<div class="post-metadata">

**Author:** ![Avansay](https://awshq.com/letter_avatar_proxy/v4/letter/a/4bbf92/32.png) [@Avansay](https://awshq.com/u/Avansay)\
**Post date:** [November 18, 2025, 3:32pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/6 "2025-11-18T15:32:38Z")

</div>

> [@Drumedor](#):
>
> It doesn’t. The message group Id puts the messages into different lanes, and then it processes the messages within each lane in the order they arrived, so if you send the invoice message first, the invoice will be …

ok, this is how i understood it. maybe i’m misunderstanding how chatgpt is trying to explain it or something. thanks

---

<div class="post-metadata">

**Author:** ![Avansay](https://awshq.com/letter_avatar_proxy/v4/letter/a/4bbf92/32.png) [@Avansay](https://awshq.com/u/Avansay)\
**Post date:** [November 18, 2025, 3:33pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/7 "2025-11-18T15:33:33Z")

</div>

> [@Drumedor](#):
>
> It doesn’t. The message group Id puts the messages into different lanes, and then it processes the messages within each lane in the order they arrived, so if you send the invoice message first, the invoice will be …

so if a system publishes 2 events to event bridge in order

then they get mis ordered to EB to SQS because EB is pubsub then they will just be out of order at SQS

---

<div class="post-metadata">

**Author:** ![ziroux](https://awshq.com/letter_avatar_proxy/v4/letter/z/f07891/32.png) [@ziroux](https://awshq.com/u/ziroux)\
**Post date:** [November 18, 2025, 3:34pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/8 "2025-11-18T15:34:40Z")

</div>

If my coworker asked that, my response would be something like: instead of asking the chat you could spend that time reading the docs. Also why wait? You can process purchase and invoice separately, as it pours from the sqs in whatever order

---

<div class="post-metadata">

**Author:** ![otterley](https://awshq.com/letter_avatar_proxy/v4/letter/o/a5b964/32.png) [@otterley](https://awshq.com/u/otterley)\
**Post date:** [November 18, 2025, 3:35pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/9 "2025-11-18T15:35:51Z")

</div>

You can find a complete explanation in the documentation for SQS FIFO queues here: [https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fifo-queues.html](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fifo-queues.html)

---

<div class="post-metadata">

**Author:** ![Drumedor](https://awshq.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@Drumedor](https://awshq.com/u/Drumedor)\
**Post date:** [November 18, 2025, 3:37pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/10 "2025-11-18T15:37:22Z")

</div>

> [@ziroux](#):
>
> If my coworker asked that, my response would be something like: instead of asking the chat you could spend that time reading the docs. Also why wait? You can process purchase and invoice separately, as it pours from the …

There might be demands within the receiving ERP that the purchase order needs to be created before the invoice is created, but that should be solved in another way than fifo-queues.

---

<div class="post-metadata">

**Author:** ![Drumedor](https://awshq.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@Drumedor](https://awshq.com/u/Drumedor)\
**Post date:** [November 18, 2025, 3:38pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/11 "2025-11-18T15:38:31Z")

</div>

> [@Avansay](#):
>
> so if a system publishes 2 events to event bridge in order then they get mis ordered to EB to SQS because EB is pubsub then they will just be out of order at SQS

Yes, the fifo SQS only cares about when the message is added to the queue, not what happened in some other system before.

---

<div class="post-metadata">

**Author:** ![voidwaffle](https://awshq.com/letter_avatar_proxy/v4/letter/v/dbc845/32.png) [@voidwaffle](https://awshq.com/u/voidwaffle)\
**Post date:** [November 18, 2025, 3:44pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/12 "2025-11-18T15:44:23Z")

</div>

> [@ziroux](#):
>
> If my coworker asked that, my response would be something like: instead of asking the chat you could spend that time reading the docs. Also why wait? You can process purchase and invoice separately, as it pours from the …

Even better, have the chat generate some test code and actually test the documented behavior for you. This isn’t some complicated edge case and the LLMs + their corresponding wrappers just aren’t that good at even a moderate understanding of how the major CSPs work as it stands today.

---

<div class="post-metadata">

**Author:** ![solo964](https://awshq.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@solo964](https://awshq.com/u/solo964)\
**Post date:** [November 18, 2025, 3:56pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/13 "2025-11-18T15:56:40Z")

</div>

> [@Drumedor](#):
>
> It doesn’t. The message group Id puts the messages into different lanes, and then it processes the messages within each lane in the order they arrived, so if you send the invoice message first, the invoice will be …

I would rephrase “if you send the invoice message first, the invoice will be processed first” to “if the invoice message is received by SQS first then the invoice will be processed first.”

---

<div class="post-metadata">

**Author:** ![Avansay](https://awshq.com/letter_avatar_proxy/v4/letter/a/4bbf92/32.png) [@Avansay](https://awshq.com/u/Avansay)\
**Post date:** [November 18, 2025, 4:00pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/14 "2025-11-18T16:00:15Z")

</div>

> [@ziroux](#):
>
> If my coworker asked that, my response would be something like: instead of asking the chat you could spend that time reading the docs. Also why wait? You can process purchase and invoice separately, as it pours from the …

i read the documentation and then ran through some examples w/ chat and it gave me some confusing answers. this is why i’m here. as was mentioned in another comment there are various reasons in different types of events where order matters. also why we’re looking at FIFO

---

<div class="post-metadata">

**Author:** ![Ok-Data9207](https://awshq.com/letter_avatar_proxy/v4/letter/o/b487fb/32.png) [@Ok-Data9207](https://awshq.com/u/Ok-Data9207)\
**Post date:** [November 18, 2025, 4:02pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/15 "2025-11-18T16:02:11Z")

</div>

I cannot tell you how exactly it’s works internally in SQS but you can read how order guarantees are done in Kafka or ActiveMQ.

Usually a metadata service/logic is involved which tracks the order of messages and its consumption. And with distributed system same data is replicated using different algorithms.

---

<div class="post-metadata">

**Author:** ![davvblack](https://awshq.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@davvblack](https://awshq.com/u/davvblack)\
**Post date:** [November 18, 2025, 4:12pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/16 "2025-11-18T16:12:46Z")

</div>

> [@Drumedor](#):
>
> They are using message group Id which is only a thing for fifo queues, which do guarantee ordering.

that’s not true anymore, you can use message group ids with standard to get “fair queues”: [https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html)

---

<div class="post-metadata">

**Author:** ![davvblack](https://awshq.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@davvblack](https://awshq.com/u/davvblack)\
**Post date:** [November 18, 2025, 4:14pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/17 "2025-11-18T16:14:31Z")

</div>

are you using FIFO or standard? a lot of answers in this thread neglect the new feature Fair Queues:

[https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fair-queues.html](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fair-queues.html)

---

<div class="post-metadata">

**Author:** ![ziroux](https://awshq.com/letter_avatar_proxy/v4/letter/z/f07891/32.png) [@ziroux](https://awshq.com/u/ziroux)\
**Post date:** [November 18, 2025, 4:28pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/18 "2025-11-18T16:28:23Z")

</div>

> [@Drumedor](#):
>
> There might be demands within the receiving ERP that the purchase order needs to be created before the invoice is created, but that should be solved in another way than fifo-queues.

Yeah fifo is cool, but still risky. What if a message doesn’t reach the queue, or in any way the order is wrong? What about retries, dlq? Are orders and invoices on the same queue? Smells like state. Maybe split them into two. Emit order, process order, emit invoice, process invoice. Dunno, a lot of possibilities how to solve this on aws for different infras. Lambdas, dynamo, events, what are you doing step functions, sns… The aws architecture blog might help a bit.

---

<div class="post-metadata">

**Author:** ![Quinnypig](https://awshq.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quinnypig](https://awshq.com/u/Quinnypig)\
**Post date:** [November 18, 2025, 4:39pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/19 "2025-11-18T16:39:59Z")

</div>

> [@Avansay](#):
>
> ok, this is how i understood it. maybe i’m misunderstanding how chatgpt is trying to explain it or something. thanks

ChatGPT often gets nuances like this wrong. It’s not well understood / explained.

---

<div class="post-metadata">

**Author:** ![Avansay](https://awshq.com/letter_avatar_proxy/v4/letter/a/4bbf92/32.png) [@Avansay](https://awshq.com/u/Avansay)\
**Post date:** [November 18, 2025, 4:41pm UTC](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774/20 "2025-11-18T16:41:13Z")

</div>

> [@ziroux](#):
>
> Yeah fifo is cool, but still risky. What if a message doesn’t reach the queue, or in any way the order is wrong? What about retries, dlq? Are orders and invoices on the same queue? Smells like state. Maybe split them …

all of these are good things to think about, i was specifically trying to make sure i understand the ordering rules.

[Next page](https://awshq.com/t/how-does-sqs-know-to-wait-for-message-1-when-message-2-arrives-first-for-a-group-id/20774.md?page=2)
