Message ordering details for FIFO topics - Amazon Simple Notification Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Message ordering details for FIFO topics

An Amazon SNS FIFO topic always delivers messages to subscribed Amazon SQS queues in the exact order in which the messages are published to the topic, and only once. With an Amazon SQS FIFO queue subscribed, the consumer of the queue receives the messages in the exact order in which the messages are delivered to the queue, and no duplicates. With an Amazon SQS standard queue subscribed, however, the consumer of the queue may receive messages out of order, and more than once. This enables further decoupling of subscribers from publishers, giving subscribers more flexibility in terms of message consumption and cost optimization, as shown in the following diagram, based on the FIFO topics example use case.

Strictly ordered message delivery in an auto parts ecommerce platform.

Note that there is no implied ordering of the subscribers. The following example shows that message m1 is delivered first to the wholesale subscriber and then to the retail subscriber and then to the analytics subscriber. Message m2 is delivered first to the retail subscriber and then to the wholesale subscriber and finally to the analytics subscriber. Though the two messages are delivered to the subscribers in a different order, message ordering is preserved for each Amazon SQS FIFO subscriber. Each subscriber is perceived in isolation from any other subscribers.

Strictly ordered message delivery for each subscriber.

If an Amazon SQS queue subscriber becomes unreachable, it can get out of sync. For example, say the wholesale application queue owner mistakenly changes the Amazon SQS queue policy in a way that prevents the Amazon SNS service principal from delivering messages to the queue. In this case, price update deliveries to the wholesale queue fail, while the ones to the retail and analytics queues succeed, causing the subscribers to be out of sync. When the wholesale application queue owner corrects its queue policy, Amazon SNS resumes delivering messages to the subscribed queue. Any messages published to the topic that target the incorrectly configured queue are dropped, unless the corresponding subscription has a dead-letter queue configured.

The wholesale queue subscriber becomes temporarily unreachable.

You can have multiple applications (or multiple threads within the same application) publishing messages to an SNS FIFO topic in parallel. When you do this, you effectively delegate message sequencing to the Amazon SNS service. To determine the established sequence of messages, you can check the sequence number.

The sequence number is a large, non-consecutive number that Amazon SNS assigns to each message. The length of the sequence number is 128-bits, and continues to increase for each Message Group. The sequence number is passed to the subscribed Amazon SQS queues as part of the message body. However, if you enable raw message delivery, the message that's delivered to the Amazon SQS queue doesn't include the sequence number or any other Amazon SNS message metadata.

Amazon SNS assigns a unique sequence number to each message and passes the sequence number to Amazon SQS.

Amazon SNS FIFO topics define ordering in the context of a message group. For more information, see Message grouping for FIFO topics.