Nov 18, 20266 min read

SNS FIFO Topics: Ordered Fan-Out to SQS FIFO Queues

How SNS FIFO topics order and deduplicate messages, what message groups and the high-throughput mode change, and how to set up a FIFO topic with SQS FIFO subscribers by hand or from an ordered topic in code.

Illustration for SNS FIFO Topics: Ordered Fan-Out to SQS FIFO Queues

SNS FIFO topics exist for the case where several consumers need the same events in the same order: an order service publishes created, paid and shipped for each order, and every consumer, from the email worker to the warehouse, needs to see them in that sequence.

A standard SNS topic fanning out to standard SQS queues gives no ordering at all, so the warehouse can see shipped before paid and has to buffer or reject it.

This guide covers how SNS FIFO ordering and deduplication work, the throughput limits that come with them, a CLI setup with SQS FIFO subscribers, and how an ordered topic declared in code maps onto the same AWS resources.

SNS FIFO at a glance

Encore ordered topicSNS FIFO topicSNS standard topic
OrderingPer value of the orderingAttribute fieldPer message group IDNone
DeduplicationNot on publish; handlers stay idempotent5-minute window, by ID or content hashNone
SubscribersSubscriptions declared in codeSQS FIFO (ordered), SQS standard (unordered)SQS, Lambda, HTTP, email, SMS and more
Throughput300 messages per second per topic on AWS, per the docs300 per group, 3,000 per topic by defaultVery high
Local developmentIn memory under encore run, ordering not enforcedNeeds AWS or an emulatorNeeds AWS or an emulator

How ordering and deduplication work

Every publish to a FIFO topic carries a MessageGroupId. Per the message grouping docs, SNS delivers different groups in parallel and keeps strict order inside each group, and it passes the group ID on to subscribed SQS FIFO queues, which then hand one group's messages to consumers one at a time. Use the entity that needs ordering, such as the order ID, as the group ID. A single constant group ID gives you global order and caps you at one group's throughput.

Deduplication is either explicit, with a MessageDeduplicationId per publish, or content-based, where SNS hashes the message body. A second publish with the same ID inside the 5-minute interval is accepted but not delivered. That protects you from a publisher retry after a timeout; it does not protect you from a consumer that processes a message, crashes before deleting it, and sees it again after the SQS visibility timeout. Consumers still need to be idempotent.

Throughput limits

By default an SNS FIFO topic delivers up to 300 messages per second per message group and 3,000 per topic. As of January 2025 you can set the topic attribute FifoThroughputScope to MessageGroup, which narrows deduplication to each message group and lets throughput scale with the number of groups, up to account-level defaults that vary by region. Per the high-throughput docs, that switch is one-way, and AWS recommends enabling high throughput on the subscribed SQS FIFO queues too.

Set up a FIFO topic with an SQS FIFO subscriber

Topic and queue names must end in .fifo, and the queue needs a policy that lets the topic send to it.

~
$ aws sns create-topic --name order-events.fifo \ --attributes FifoTopic=true,ContentBasedDeduplication=false$ aws sqs create-queue --queue-name ledger.fifo \ --attributes FifoQueue=true$ aws sqs set-queue-attributes --queue-url $LEDGER_QUEUE_URL \ --attributes file://ledger-queue-policy.json$ aws sns subscribe --topic-arn $TOPIC_ARN --protocol sqs \ --notification-endpoint $LEDGER_QUEUE_ARN \ --attributes RawMessageDelivery=true

The queue policy allows sqs:SendMessage for the sns.amazonaws.com principal with an aws:SourceArn condition on the topic ARN. Each additional consumer is another FIFO queue, another policy and another subscription, plus a dead-letter queue (which must also be FIFO) with a redrive policy, as in SNS with Terraform.

Publishing sets the group ID and, without content-based deduplication, a deduplication ID:

import { SNSClient, PublishCommand } from "@aws-sdk/client-sns"; const sns = new SNSClient({}); export async function publishOrderEvent(orderId: string, status: string, eventId: string) { await sns.send(new PublishCommand({ TopicArn: process.env.ORDER_EVENTS_TOPIC_ARN!, Message: JSON.stringify({ orderId, status }), MessageGroupId: orderId, // order is kept per order MessageDeduplicationId: eventId, // the same event published twice is delivered once })); }

On the consumer side, a failing message blocks the rest of its group until it succeeds or moves to the dead-letter queue. That head-of-line blocking is the price of ordering, so alert on DLQ depth and keep handlers fast.

Ordered topics in Encore

Encore

Encore brings infrastructure from code to the publisher and its consumers, and an ordered topic is one field on the topic declaration. You mark a top-level field as an Attribute and name it as the orderingAttribute; messages with the same value are delivered to each subscription in publish order. On deploy to your own AWS account Encore provisions SNS and SQS with dead-letter queues and provisions an IAM role for the service, and the runtime publishes with that attribute value as the SNS message group ID. On GCP the same declaration uses Pub/Sub ordering keys.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

// orders/events.ts import { Topic, Subscription, Attribute } from "encore.dev/pubsub"; import { SQLDatabase } from "encore.dev/storage/sqldb"; const db = new SQLDatabase("ledger", { migrations: "./migrations" }); export interface OrderEvent { orderId: Attribute<string>; eventId: string; status: "created" | "paid" | "shipped"; } export const orderEvents = new Topic<OrderEvent>("order-events", { deliveryGuarantee: "at-least-once", orderingAttribute: "orderId", }); const _ = new Subscription(orderEvents, "ledger", { handler: async (e) => { // Idempotent on eventId: publish does not deduplicate. await db.exec` INSERT INTO order_status_log (event_id, order_id, status) VALUES (${e.eventId}, ${e.orderId}, ${e.status}) ON CONFLICT (event_id) DO NOTHING`; }, });

The docs list the trade-offs plainly: on AWS an ordered topic is limited to 300 messages per second for the topic, messages with the same key wait behind a failing one until it is processed or dead-lettered, and the orderingAttribute has no effect under encore run, so ordering is only enforced after deploy, although each publish and delivery still appears in the local trace. Encore does not add a deduplication window on publish, which is why the handler above keys its insert on eventId.

A coding agent can add a new subscriber to the ordered topic in the same change as the code that needs it, without creating a FIFO queue, a queue policy and a DLQ by hand.

Best fit: TypeScript or Go backends that need per-entity ordering across several consumers in their own AWS or GCP account, at hundreds rather than tens of thousands of messages per second.

When to use SNS FIFO

Use SNS FIFO when more than one consumer needs the same events in order per entity, and choose a group ID with enough distinct values to spread the load. Use a standard topic when consumers can tolerate reordering, which is most notification and analytics work. If you only have one consumer, a single SQS FIFO queue without SNS is simpler, as covered in SQS FIFO vs standard.

Frequently asked questions

What is an SNS FIFO topic?

An SNS FIFO topic is an SNS topic whose name ends in .fifo and that preserves publish order within each message group ID and drops duplicates within a 5-minute deduplication interval. It fans out to SQS FIFO queues, which keep that order for each consumer. Standard SQS queues can also subscribe, but they do not receive the message group ID and do not keep order.

How fast can an SNS FIFO topic go?

By default an SNS FIFO topic delivers up to 300 messages per second per message group and 3,000 per topic. Setting FifoThroughputScope to MessageGroup enables high-throughput mode, which moves deduplication to the message-group level and scales with the number of distinct groups; the change cannot be reverted.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders