Overview
Amazon SNS (Simple Notification Service) is a managed pub/sub service. Publishers send messages to a topic, and SNS pushes a copy to every subscriber: SQS queues, Lambda functions, HTTP endpoints, email, SMS, or mobile push. Subscription filter policies let each subscriber receive only the messages it cares about.
The most common architecture is SNS-to-SQS fan-out: one topic per event type, with each consuming service owning an SQS queue subscribed to it. SNS provides the broadcast, and SQS provides durable buffering, retries, and dead-letter queues per consumer.
An announcement is made once over loudspeakers, and everyone in each room hears it. SNS is the PA system; SQS queues are rooms with answering machines that record the announcement for people who are away.
When to use it
- Fan-out of events to multiple AWS services.
- Sending notifications via SMS, email, or mobile push.
- Alerting from CloudWatch alarms.
- Simple event broadcasting without running brokers.
Where it shows up in interviews
Recognize it when: one event, several consumers on AWS.
- Design order processing on AWS
- Design an upload pipeline with multiple processors
Recognize it when: send SMS or push at scale.
- Design a notification service
- Design OTP delivery
Where it is used in real software
Alarms publish to SNS topics that page on-call engineers or trigger automation.
SNS sends push notifications via APNs and FCM.
S3 can publish object-created events to SNS for fan-out to multiple processors.
Key terms
- Topic
- Named channel for publishing.
- Subscription
- Endpoint that receives messages from a topic.
- Filter policy
- Attribute rules deciding which messages a subscriber gets.
- FIFO topic
- Ordered, deduplicated delivery to FIFO SQS queues.
- Delivery retry policy
- Retries for HTTP and other push endpoints.
How it works, step by step
- 1Create a topic
For example order-events.
- 2Subscribe endpoints
SQS queues per service, Lambda, HTTP.
- 3Add filter policies
Only OrderShipped to the email service.
- 4Publish with attributes
type = OrderShipped.
- 5SNS pushes copies
Retries failed deliveries; DLQs capture undeliverable messages.
SNS vs SQS vs EventBridge
AWS messaging services
| Service | Model | Delivery | Best for |
|---|---|---|---|
| SNS | Pub/sub push | Fan-out to many | Broadcast, notifications |
| SQS | Queue pull | One consumer per message | Buffering, work distribution |
| EventBridge | Event bus with rules | Rule-based routing | Event-driven integrations, SaaS events |
| Kinesis | Stream | Ordered shards, replay | High-volume streaming analytics |
NOWService: SNS | Model: Pub/sub push | Delivery: Fan-out to many | Best for: Broadcast, notifications
SNS + SQS is the classic fan-out combination; EventBridge adds content-based routing and schema discovery.
Implementation
{ "type": ["OrderShipped", "OrderDelivered"], "country": ["US", "CA"], "totalCents": [{ "numeric": [">=", 10000] }]}Complexity and performance
Managed by AWS.
Same as SQS.
Trade-offs
SNS alone does not retain messages for offline consumers; pair with SQS for durability.
Filter policies cover common cases; EventBridge offers richer routing and archives.
Variants and related techniques
Ordered fan-out to FIFO queues.
Available for FIFO topics.
Common mistakes
- Subscribing Lambdas directly without DLQs.
Fix: Configure DLQs or use SQS in between.
- Putting routing logic in every consumer.
Fix: Use filter policies so consumers receive only what they need.
Interview questions
Why use SNS with SQS instead of SNS alone?
SNS pushes messages immediately and does not buffer for slow or offline consumers. SQS queues give each consumer durable storage, independent pacing, retries, and DLQs.
How would you send order-shipped notifications by email and push?
Publish OrderShipped to an SNS topic; subscribe an email-worker queue and a push-worker queue with filter policies; each worker formats and sends through its provider.
Practice problems
| Problem | Difficulty | What it trains |
|---|---|---|
| Design SNS + SQS fan-out for an upload pipeline | Easy | Fan-out. |
| Design an alerting pipeline with SNS | Medium | Routing and escalation. |