Skip to main content

Amazon SNS (Simple Notification Service)

Core concept: SNS is a pub/sub service โ€” one message published to a Topic is pushed to all subscribers simultaneously (fan-out).


SNS vs SQSโ€‹

FeatureSNSSQS
ModelPush (pub/sub)Pull (queue)
PersistenceโŒ No (messages not stored)โœ… Yes (up to 14 days)
ConsumersMany at once (all subscribers)One consumer per message
Use caseFan-out, alerts, notificationsDecoupling, buffering

Subscription Typesโ€‹

ProtocolUse Case
SQSFan-out to a queue for async processing
LambdaDirect serverless processing
HTTP/HTTPSWebhook delivery
Email / Email-JSONHuman notifications
SMSMobile text messages
Mobile PushAPNs (iOS), FCM (Android), ADM

Fan-Out Pattern (SNS + SQS)โ€‹

          [S3 Event / App]
โ”‚
โ–ผ
[SNS Topic]
/ โ”‚ \
โ–ผ โ–ผ โ–ผ
[SQS] [SQS] [Lambda]
Queue Queue
(ETL) (Audit) (Alert)

Why not publish to multiple SQS directly? โ†’ SNS fan-out is atomic: one publish โ†’ all subscribers in parallel. โ†’ Adding new consumers doesn't change the producer.


Message Filteringโ€‹

Each SQS subscription can define a filter policy so it only receives relevant messages:

// Subscription filter โ€” only receive orders from "electronics" category
{
"category": ["electronics"],
"price": [{ "numeric": [">=", 100] }]
}

Messages are published with message attributes, and SNS only delivers to matching subscriptions.


SNS FIFOโ€‹

  • Ordered messages to SQS FIFO subscribers only
  • Supports deduplication (same as SQS FIFO)
  • Topic name must end in .fifo
  • Lower throughput than standard SNS

๐Ÿงช Practice Questionsโ€‹

Q1. An e-commerce app publishes an OrderPlaced event. Three services need to process it: inventory, billing, and shipping. What is the BEST architecture?

A) One SQS queue per service, application publishes to all 3
B) SNS Topic โ†’ 3 SQS subscriptions (fan-out)
C) Kinesis Data Stream
D) Direct Lambda invocation from the order service

โœ… Answer & Explanation

B โ€” The SNS fan-out pattern (SNS โ†’ multiple SQS queues) is the standard answer for "multiple consumers need the same event." Each service gets its own queue, decoupling processing speed and failure domains.


Q2. A notification system needs to send alerts via email to admins and via SMS to on-call engineers from the same alert. What SNS feature enables this?

A) Message Filtering
B) Multiple Subscriptions on one Topic
C) SNS FIFO
D) Dead Letter Queue

โœ… Answer & Explanation

B โ€” SNS Topics support multiple subscriptions with different protocols. One email subscription + one SMS subscription receives every published message.


๐Ÿ”— Resourcesโ€‹