Course contentsShow
← System Design
Lesson 670 of 1,91918. Message Queues and BrokersFree lesson

Amazon SNS and SNS-SQS Integration

Pub-sub with SNS, fan-out patterns, and combining SNS with SQS for flexible routing.

Amazon SNS and SNS-SQS Integration

What you'll learn: How Amazon SNS enables pub-sub messaging and how combining SNS with SQS creates powerful, flexible routing patterns.

What Is Amazon SNS?

Amazon Simple Notification Service (SNS) is AWS's managed pub-sub messaging service. When you publish a message to an SNS topic, it automatically delivers copies to all subscribers—which can be email addresses, HTTP endpoints, Lambda functions, mobile push notifications, or SQS queues.

Think of SNS as a loudspeaker system: one announcement (message) reaches everyone listening (subscribed) simultaneously.

The Fan-Out Pattern

SNS excels at fan-out—broadcasting one message to multiple destinations. Instead of your application sending the same message to five different services, you publish once to SNS and it handles distribution. This dramatically simplifies your code and reduces coupling.

SNS-SQS Integration: Best of Both Worlds

Here's where it gets powerful: subscribe multiple SQS queues to a single SNS topic.

When you integrate SNS with SQS:

  • SNS handles the pub-sub broadcasting (one-to-many)
  • Each SQS queue buffers messages for its specific consumer
  • Individual services process messages at their own pace
  • Failed processing doesn't affect other subscribers

Example scenario: An order placed event gets published to SNS. It fans out to:

  • An SQS queue for the inventory service (to reserve stock)
  • An SQS queue for the email service (to send confirmation)
  • An SQS queue for analytics (to track metrics)

Each service gets reliable, asynchronous delivery with independent retry logic and backpressure handling.

Filtering for Precision

SNS supports subscription filters—routing messages to specific queues based on message attributes. This lets you build sophisticated routing logic without custom code.

Key Takeaway: Amazon SNS provides managed pub-sub with fan-out capabilities, and combining SNS topics with SQS queues creates a highly flexible, decoupled architecture where broadcasts meet reliable, buffered consumption.