← Dashboard
Section 04 of 14

The Queue

What This Does

After an order qualifies, it's dropped into an AWS SQS FIFO queue — think of it as a single-file waiting line. The queue ensures orders are processed one at a time per merchant, prevents duplicates, and decouples the webhook handler (fast, returns immediately) from the actual processing (slow, talks to ShipStation API).

Why It Matters

Without a queue, the webhook handler would have to do all the processing synchronously — and Shopify expects webhook responses within 5 seconds. The actual processing (fetching from Shopify, calling ShipStation, verifying) can take 30+ seconds. The queue lets the webhook return instantly while processing happens in the background.

How It Works

  1. 1.An order is enqueued with a message body containing: shopId, shopifyOrderId, shopifyOrderNumber, timestamp, and optionally an 'approved' flag.
  2. 2.MessageGroupId is set to the shopId — this means SQS processes orders for each merchant in sequence (FIFO = First In, First Out). Two orders from the same merchant won't process simultaneously.
  3. 3.MessageDeduplicationId is set to the shopifyOrderId — this prevents the same order from being enqueued twice within the deduplication window (5 minutes).
  4. 4.For approved re-enqueue (from the review queue), '-approved' is appended to the dedup ID so it doesn't collide with the original message.
  5. 5.A Lambda function (the 'worker') polls the queue and processes each message.

The Code

Key Decisions

What Could Go Wrong