1 December 2026 · 3 min read · Download as PDF

The consumer is where reliability becomes real

A queue stores work, but the worker decides when it is done. Visibility timeouts, partial batch responses, idempotency and backlog alarms turn delivery into dependable processing.

Part 4 of 6 · From Event to Outcome: AWS Messaging Patterns

Cover: The consumer is where reliability becomes real

The fulfilment queue has a message. That sounds like the hard part is over. It is not: a consumer may time out after starting work, receive the same message again and repeat a side effect. The same problem exists inside a workflow task that reserves stock. Messaging services can retry delivery; they cannot decide whether an application side effect is safe to repeat.

Part 4 of 6 in From Event to Outcome, a series on AWS messaging patterns.

Where this fits. A queue from Part 3 now contains work. A Lambda worker can poll an independent queue directly. The fulfilment path in this example uses a Pipe to start a workflow, and the stock task inside it still needs the same discipline when a retry could reserve stock twice. Part 5 shows where that workflow starts and who owns failures after launch.

An SQS delivery reaches a worker. On success the message is deleted. If visibility expires the message can be retried, and repeated failures can lead to a dead-letter queue.

TL;DR

  • Simple Queue Service (SQS) standard queues deliver at least once and do not promise strict ordering. Build an idempotent consumer.
  • With Lambda as a queue consumer, the event source mapping polls SQS. Messages stay hidden during the visibility timeout and are removed after successful processing.
  • Turn on partial batch responses when processing records independently, so one bad record does not force successful records through the worker again.
  • Monitor oldest message age, queue depth, failed invocations and DLQ arrivals. Count record failures separately when the function returns a partial batch response.

Make stock reservation safe to retry

The stock task uses a business idempotency key such as orderId + reservationStep. Before reserving stock, it checks or conditionally writes a record that says whether that step has already completed. If a retry finds the completed record, it returns success without a second reservation. The event ID is useful for tracing duplicates, but the business key expresses the side effect being protected. A Lambda worker reading a queue needs the same discipline for its own side effects.

The conditional update and the stock change must be designed together. A “processed” flag written too early can lose work; a flag written too late can repeat it. For a multi-step business operation, Step Functions may be a better place to manage the state, but the individual task still needs safe retry behaviour.

Visibility, batches and ordering

When Lambda reads from SQS, it can receive a batch. By default, one record failing can make the whole batch visible again. AWS supports ReportBatchItemFailures so the function can report only failed records. For a straightforward first in, first out (FIFO) batch handler, follow AWS Lambda’s guidance: stop at the first failure and return the failed record and all unprocessed records in batchItemFailures. A top-level exception makes Lambda treat the whole batch as failed.

Set the visibility timeout before raising the Lambda timeout. AWS’s SQS integration guide recommends at least six times the function timeout, plus any batching window. A timeout shorter than the real processing time lets another worker see the message while the first one is still running.

What the dashboard should answer

How old is the oldest unprocessed order? Is the queue growing faster than workers drain it? Are messages landing in the DLQ? Is the workflow starting but later failing? Those are separate signals. Give each queue a runbook: who is paged, what may be retried and which side effects must be checked before redrive.

Next: how a queue or event starts a Step Functions workflow, and which completion signal each route actually gives you.

From Event to Outcome

  1. SQS, SNS and EventBridge: choose by the job (Amazon Simple Queue Service, Simple Notification Service and EventBridge)
  2. Publishing an event without losing the order
  3. Fan-out without coupling every consumer
  4. The consumer is where reliability becomes real (you’re here)
  5. Events into Step Functions: rule, pipe or API?
  6. Fan-in, recovery and the end of the event story

More from the blog