SNS Topics, Subscriptions, Filtering, and Fan-Out
coreintermediateA topic is a named channel a publisher sends messages to, without knowing who — if anyone — is listening. A subscription attaches one delivery target (SQS, Lambda, HTTP(S), email, SMS, mobile push) to a topic; every subscription gets its own copy of each message. A filter policy on a subscription drops messages that do not match, so one topic can serve subscribers that each want a different subset. Fan-out is what happens when a topic has multiple subscriptions: one publish reaches every matching subscriber in parallel.
Think of it as
A topic is a mailing list, not a mailbox. The publisher drops one message in the list; SNS photocopies it and delivers one copy to every current subscriber, each independently, each on its own retry schedule. Adding or removing a subscriber never touches the publisher's code.
What we're doing: Filter a topic so only high-priority orders reach a paging subscriber, while a logging subscriber still sees every order.
- 2
- This subscription receives a message only if its "priority" message attribute is "high" or "urgent" — every other publish to the topic is skipped for this subscriber.
Why this works: The filter lives on the subscription, not the topic, so the same topic and the same publish call can serve a narrowly-filtered subscriber (paging) and a see-everything subscriber (logging) at once — the publisher never needs to know either one exists.
Putting routing logic in the publisher instead of a filter policy
Wrong
Better
What you see: Every new subscriber that wants a different subset of orders requires a code change and a redeploy of the publisher, and the publisher accumulates a growing list of topic ARNs and if/else branches.
Why: A filter policy moves the "who wants this message" decision to the subscriber side, which is what fan-out is for — the publisher publishes once, to one topic, and stays unaware of how many subscribers exist or what they each care about.
- Publisher
- leads to SNS topic (Publish(message))
- SNS topic
- leads to SQS subscriber (matches filter)
- leads to Lambda subscriber (matches filter)
- leads to Email subscriber (no filter — gets everything)
- SQS subscriber
- Lambda subscriber
- Email subscriber
Remember: Topic = named channel; subscription = one delivery target attached to it, each with its own filter policy and retry schedule. Fan-out is one publish reaching every matching subscriber in parallel. Client-side errors are not retried; server-side errors retry per-protocol (SQS/Lambda: ~23 days; SMTP/SMS/push: ~6 hours) before being discarded — attach a DLQ per subscription to catch what would otherwise be lost.
See also: sns sqs fanout pattern

