AWS SQS and SNS for Ordered Order Processing

Follow ordered order processing through SNS FIFO and SQS FIFO, with the limits of deduplication, idempotent effects, visibility timeouts, retries, and DLQs.

published: reading time: 7 min read author: Geek Workbench updated: November 5, 2026
Quick Summary

Follow an order event through SNS FIFO, SQS FIFO, and a payment worker. FIFO can suppress duplicate sends and preserve per-group order, but the worker still needs idempotency for charges and database writes.

AWS SQS and SNS for Ordered Order Processing

A customer submits an order. The service publishes an OrderSubmitted event, and a payment worker processes it. If the same order gets several events, they must be handled in sequence. If the worker crashes after charging the card but before acknowledging the message, a retry must not charge the customer again.

This guide follows that path through an SNS FIFO topic and an SQS FIFO queue. SNS is useful when several independent systems need the event; each can have its own queue and retry policy. If only one worker group needs the message, send directly to SQS and skip the topic.

Route one order event

Publish OrderSubmitted to an SNS FIFO topic, then deliver it to the payment worker’s SQS FIFO queue. If inventory or fulfillment also needs the event, subscribe another SQS FIFO queue. Each order queue can then retry independently.

Set MessageGroupId to the order ID. FIFO preserves sequence within a message group, so OrderSubmitted and later events for that order cannot pass one another in the queue. Different order IDs can be processed in parallel. A single group for every order would serialize the entire workload.

Use a stable event ID as the MessageDeduplicationId when publishing. In this path, SNS FIFO suppresses a repeat publish within its documented five-minute interval. A producer that sends directly to SQS FIFO gets the queue’s own five-minute deduplication interval. AWS documentation for SQS FIFO deduplication was checked on November 5, 2026. With content-based deduplication, AWS hashes the message body, not message attributes. If two distinct business events can have the same body, include their identity in the body or provide an explicit deduplication ID.

Deduplicating a send is not the same as applying a business effect once. The same payment request can still reach a worker again after an error, timeout, or crash. Treat the event ID as an idempotency key at the consumer too.

Where the delivery guarantee stops

AWS documents conditional exactly-once delivery and processing for an SNS FIFO topic subscribed to by an SQS FIFO queue. All of these conditions must hold:

  • The SQS FIFO queue exists and its policy lets the SNS service deliver messages.
  • The consumer processes and deletes the message before its visibility timeout expires.
  • The SNS subscription has no message filter. With filtering enabled, SNS FIFO delivery is at-most-once because messages can be filtered out.
  • No network disruption prevents delivery acknowledgement.

See the SNS FIFO deduplication rules for the full conditions. FifoThroughputScope also matters: SNS can scope deduplication to the topic or to each message group. A deduplication ID repeated within the documented five-minute interval is not delivered again within that scope. Content-based deduplication uses the body and excludes message attributes here as well.

These conditions describe the broker delivery path. They do not make a database update, external API call, or card charge happen exactly once. A worker can complete the charge and then fail before deleting the message. SQS may deliver it again.

Make the payment worker idempotent

Give every business event a durable ID, such as event_id=evt-901. Before applying an order update, check whether that event has already been recorded. For a database change, write the event ID to a processed-events table and update the order in the same database transaction, with a uniqueness constraint on the event ID. Then a retry can recognize completed work.

For a payment provider, pass the same event ID as the provider’s idempotency key when it supports one. If the provider does not support idempotency, the worker needs a reconciliation step before it retries an uncertain charge. A local database transaction cannot make a remote charge and a local write atomic.

Delete the SQS message only after the durable result has been recorded. This leaves a small but important recovery window: a crash after the charge and before DeleteMessage causes a retry. The idempotency record or provider key is what prevents a second charge.

Set visibility timeout for the work

When a consumer receives a message, SQS keeps it in the queue but hides it from other consumers for the visibility timeout. If the worker does not delete it before that timeout expires, SQS makes it visible again. In a FIFO queue, later messages in the same group wait until the current message is deleted or its timeout expires. The SQS visibility timeout guide also notes that visibility does not absolutely prevent duplicate delivery.

Choose a timeout that covers observed processing time and normal variance. A timeout that is too short can let a second worker receive the event while the first still runs; one that is too long delays another attempt after a crash. For work that sometimes runs longer, extend visibility with ChangeMessageVisibility while processing, then delete after the result is committed.

Send repeated failures to a DLQ

Configure a redrive policy with a maxReceiveCount so a message that repeatedly fails moves to a dead-letter queue. Alert on DLQ depth, inspect the event and logs, fix the cause, and redrive messages deliberately. Preserve the event ID so the idempotency check still works during replay. See Using dead-letter queues in SQS.

A DLQ can change the order of work in a FIFO group: after a failed message is moved aside, later messages may proceed. AWS warns against using a DLQ when moving a message would break the required order. If an order’s later events cannot safely pass a failed payment event, pause that order’s processing and repair or reconcile it before advancing.

Choose the queue and topic you need

Requirement Use Notes
One worker group should claim each task SQS Standard queues provide at-least-once delivery and best-effort ordering.
Events for each order must stay in sequence SQS FIFO Use the order ID as the group ID; ordering is per group, not global.
Several systems need the same event, with separate retry and failure handling SNS with one SQS queue per subscriber Choose FIFO for both topic and queues when the event flow needs per-group order.
A repeated send should be suppressed SQS or SNS FIFO deduplication This covers message sends within the documented interval, not side effects in a payment worker.

There is no generic “30,000 messages per second per subscriber” setting. SNS publish quotas are per account and Region; FIFO topic and message-group throughput also depends on FifoThroughputScope. SQS FIFO quotas depend on queue mode, Region, API operation, batching, and group distribution. The official SNS quotas and SQS message quotas were checked on November 5, 2026. Check the current quota pages for the target account and Region before sizing the path.

Keep retention settings separate

SQS message retention is a queue setting. It is not a retention period for an SNS topic. SNS FIFO has a separate, optional message archive and replay feature; it must be configured on the topic and uses its own retention policy. Check the SQS message quotas page for the queue’s allowed retention range.

For more about AWS data paths and S3, see AWS Data Services. For the wider choices between queues and pub/sub, see Message Queue Types and Pub/Sub Patterns.

Category

Related Posts

Cloud Cost Optimization: Measure, Compare, and Right-Size

A practical method for right-sizing cloud resources, evaluating commitments, tracking egress, and measuring cost per unit without relying on stale price tables.

#cloud #cost #optimization

Object Storage: S3, Blob Storage, and Scale of Data

Learn how object storage systems like Amazon S3 handle massive unstructured data, buckets, keys, metadata, versioning, and durability patterns.

#storage #s3 #cloud

AWS Data Services: Kinesis, S3, Glue, Athena, Redshift

Follow an order event from Kinesis Data Streams through S3 to Athena or Redshift, adding Glue when transformation or shared catalog metadata helps.

#data-engineering #aws #kinesis