← Dashboard
Section 05 of 14

The Worker

What This Does

The worker is an AWS Lambda function that sits between the queue and the order processor. It reads messages from SQS, calls processOrder() for each one, and decides what to do with the result: success, permanent failure (drop it), or transient failure (put it back in the queue for retry).

Why It Matters

This is the bridge between 'order is queued' and 'order is processed.' It handles the messy real-world concerns: what if the message is malformed? What if processing fails due to a network error? What if ShipStation is temporarily down? The worker classifies errors and decides whether to retry or give up.

How It Works

  1. 1.Lambda polls SQS and receives a batch of messages (configured for batch size 1 for rate limit safety).
  2. 2.For each message, it parses the JSON body into an OrderQueueMessage.
  3. 3.It calls processOrder(shopId, shopifyOrderId, approved) — the main pipeline function.
  4. 4.If processOrder succeeds, the message is acknowledged (removed from queue).
  5. 5.If processOrder fails with a TRANSIENT error (network, rate limit, 5xx), the message is returned to the queue via batchItemFailures — SQS will re-deliver it after a visibility timeout.
  6. 6.If processOrder fails with a PERMANENT error (cancelled order, bad data), the message is acknowledged so it's not retried endlessly.
  7. 7.Malformed messages (invalid JSON) are silently dropped with a log warning.

The Code

Key Decisions

What Could Go Wrong