0
0
AWScloud~15 mins

SNS topics and subscriptions in AWS - Deep Dive

Choose your learning style9 modes available
Overview - SNS topics and subscriptions
What is it?
SNS topics and subscriptions are parts of a messaging service that lets different parts of a system talk to each other by sending messages. A topic is like a channel where messages are sent. Subscriptions are the ways to receive those messages, like email, SMS, or other services. This system helps send information quickly to many receivers at once.
Why it matters
Without SNS topics and subscriptions, systems would struggle to share updates or alerts efficiently. Imagine if every message had to be sent individually to each receiver; it would be slow and error-prone. SNS solves this by letting one message reach many receivers instantly, improving communication and system responsiveness.
Where it fits
Before learning SNS topics and subscriptions, you should understand basic cloud services and messaging concepts like queues and events. After this, you can explore more complex event-driven architectures, serverless computing, and integrating SNS with other AWS services like Lambda or SQS.
Mental Model
Core Idea
SNS topics act as message broadcasters, and subscriptions are the receivers that get those messages automatically.
Think of it like...
Think of SNS topics as a radio station broadcasting music, and subscriptions as radios tuned in to that station to receive the music automatically.
┌─────────────┐       ┌───────────────┐
│ SNS Topic   │──────▶│ Subscription 1│
│ (Broadcaster)│      ├───────────────┤
└─────────────┘       │ Subscription 2│
                      ├───────────────┤
                      │ Subscription 3│
                      └───────────────┘
Build-Up - 7 Steps
1
FoundationWhat is an SNS Topic?
🤔
Concept: Introduce the idea of a topic as a message channel.
An SNS topic is a named communication channel where messages are sent. Think of it as a bulletin board where messages are posted for others to see. Publishers send messages to the topic, but the topic itself does not store messages permanently.
Result
You understand that a topic is the starting point for sending messages to multiple receivers.
Understanding that topics are central hubs for messages helps grasp how SNS organizes communication.
2
FoundationWhat is a Subscription?
🤔
Concept: Explain how subscriptions receive messages from topics.
A subscription is a way to receive messages from a topic. It can be an email address, a phone number for SMS, an HTTP endpoint, or other AWS services. When a message is sent to the topic, all subscriptions get a copy of that message automatically.
Result
You see how messages flow from a topic to multiple receivers without extra effort.
Knowing that subscriptions automate message delivery clarifies how SNS supports many receivers efficiently.
3
IntermediateCreating and Managing Topics
🤔Before reading on: do you think you can create multiple topics with the same name or must each topic have a unique name? Commit to your answer.
Concept: Learn how to create topics and the uniqueness requirement.
Each SNS topic must have a unique name within an AWS account and region. You create topics using the AWS console, CLI, or SDKs. Topics can be standard or FIFO (first-in, first-out) for ordered message delivery.
Result
You can create topics and understand naming rules and types.
Knowing topic uniqueness prevents naming conflicts and helps organize messaging channels clearly.
4
IntermediateSubscribing and Confirming Subscriptions
🤔Before reading on: do you think subscriptions start receiving messages immediately after creation, or is there a confirmation step? Commit to your answer.
Concept: Explain the subscription confirmation process.
When you create a subscription, the subscriber usually must confirm it. For example, an email subscription sends a confirmation message with a link. Only after confirmation does the subscription become active and start receiving messages.
Result
You understand the security step that prevents unwanted subscriptions.
Knowing about confirmation helps avoid confusion when messages don't arrive immediately after subscribing.
5
IntermediateMessage Delivery and Protocols
🤔Before reading on: do you think SNS guarantees message delivery to all subscriptions or can some messages be lost? Commit to your answer.
Concept: Introduce delivery protocols and reliability.
SNS supports multiple protocols like HTTP/S, email, SMS, Lambda, and SQS. Standard topics offer best-effort delivery, which means messages might occasionally be lost. FIFO topics provide exactly-once and ordered delivery but have more restrictions.
Result
You know how messages are sent and the reliability tradeoffs.
Understanding delivery guarantees helps design systems that handle message loss or ordering needs properly.
6
AdvancedFiltering Messages on Subscriptions
🤔Before reading on: do you think all subscriptions receive every message, or can they choose which messages to get? Commit to your answer.
Concept: Learn about message filtering to control delivery.
SNS allows subscriptions to have filter policies. These policies specify message attributes that decide if a subscription receives a message. This way, one topic can send different messages to different subscribers based on content.
Result
You can reduce unnecessary message delivery and tailor communication.
Knowing filtering improves efficiency and relevance of message delivery in complex systems.
7
ExpertCross-Region and Cross-Account Subscriptions
🤔Before reading on: do you think SNS topics and subscriptions can work across AWS accounts and regions? Commit to your answer.
Concept: Explore advanced use cases of SNS across boundaries.
SNS supports subscriptions that receive messages from topics in different AWS accounts or regions. This requires proper permissions and setup. It enables building global, multi-account architectures where messages flow securely and efficiently.
Result
You can design scalable, distributed messaging systems across AWS boundaries.
Understanding cross-account and cross-region capabilities unlocks powerful architectures for large organizations.
Under the Hood
SNS topics act as message routers that accept messages from publishers and then push copies to all active subscriptions. Internally, SNS manages delivery attempts, retries, and error handling. It uses protocols like HTTP/S or AWS Lambda invocation to send messages. Subscriptions maintain state about confirmation and delivery status.
Why designed this way?
SNS was designed to simplify pub/sub messaging in the cloud, avoiding the complexity of managing message brokers. It uses a push model to reduce latency and offload delivery work from publishers. The confirmation step protects subscribers from spam or unwanted messages. The design balances ease of use, scalability, and reliability.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ Publisher(s)  │──────▶│   SNS Topic   │──────▶│ Subscription 1│
└───────────────┘       │ (Router)      │       ├───────────────┤
                        │               │       │ Subscription 2│
                        └───────────────┘       └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does SNS guarantee that every message will reach all subscriptions without fail? Commit to yes or no.
Common Belief:SNS always delivers every message to all subscriptions without loss.
Tap to reveal reality
Reality:Standard SNS topics provide best-effort delivery, so messages can occasionally be lost. Only FIFO topics offer exactly-once delivery with ordering.
Why it matters:Assuming guaranteed delivery can cause data loss or missed alerts in critical systems if not designed with retries or dead-letter queues.
Quick: Can a subscription receive messages before confirming the subscription? Commit to yes or no.
Common Belief:Subscriptions start receiving messages immediately after creation, no confirmation needed.
Tap to reveal reality
Reality:Most subscription types require confirmation before messages are delivered to prevent unauthorized subscriptions.
Why it matters:Ignoring confirmation leads to confusion when messages don't arrive, causing troubleshooting delays.
Quick: Can one SNS topic send different messages to different subscribers based on message content? Commit to yes or no.
Common Belief:All subscriptions to a topic receive every message sent to that topic.
Tap to reveal reality
Reality:SNS supports message filtering so subscriptions can receive only messages matching their filter policies.
Why it matters:Not knowing filtering leads to inefficient message delivery and unnecessary processing by subscribers.
Quick: Can SNS topics be shared across AWS accounts without special setup? Commit to yes or no.
Common Belief:SNS topics and subscriptions work only within the same AWS account by default.
Tap to reveal reality
Reality:SNS supports cross-account subscriptions but requires explicit permissions and configuration.
Why it matters:Assuming no cross-account support limits architecture options for multi-account organizations.
Expert Zone
1
SNS message delivery retries use exponential backoff with jitter to avoid overwhelming endpoints during failures.
2
FIFO topics require all subscriptions to be FIFO-compatible, limiting protocol choices and increasing complexity.
3
Dead-letter queues can be attached to subscriptions to capture undeliverable messages for later analysis.
When NOT to use
SNS is not ideal when strict message ordering and guaranteed delivery are critical unless using FIFO topics. For complex workflows requiring message persistence and processing guarantees, consider AWS SQS or event streaming platforms like Kafka.
Production Patterns
In production, SNS is often combined with Lambda functions for serverless event processing, SQS queues for buffering, and CloudWatch alarms for monitoring. Filtering policies are used to route messages efficiently, and cross-account subscriptions enable multi-tenant architectures.
Connections
Event-Driven Architecture
SNS topics and subscriptions are foundational building blocks for event-driven systems.
Understanding SNS helps grasp how loosely coupled components communicate asynchronously in modern cloud applications.
Publish-Subscribe Pattern
SNS implements the publish-subscribe messaging pattern in the cloud.
Knowing SNS clarifies how publishers and subscribers interact without direct knowledge of each other.
Radio Broadcasting
SNS topics broadcasting messages to subscriptions parallels radio stations sending signals to radios.
This cross-domain connection shows how one-to-many communication works efficiently in different fields.
Common Pitfalls
#1Expecting immediate message delivery without subscription confirmation.
Wrong approach:Create subscription and assume messages start arriving instantly without confirming the subscription link.
Correct approach:Create subscription, then confirm it by clicking the link or responding to the confirmation message before expecting messages.
Root cause:Misunderstanding the subscription confirmation process leads to missed messages and confusion.
#2Using standard topics when message order and exactly-once delivery are required.
Wrong approach:Create a standard SNS topic and rely on it for ordered, guaranteed message delivery.
Correct approach:Use FIFO SNS topics with proper configuration to ensure message order and exactly-once delivery.
Root cause:Not knowing the difference between standard and FIFO topics causes unreliable message processing.
#3Sending all messages to all subscriptions without filtering.
Wrong approach:Attach all subscriptions to a topic without filter policies, causing every subscriber to receive every message.
Correct approach:Define filter policies on subscriptions to deliver only relevant messages to each subscriber.
Root cause:Ignoring filtering leads to inefficient resource use and unnecessary processing.
Key Takeaways
SNS topics are channels where messages are sent to many receivers called subscriptions.
Subscriptions must usually be confirmed before they start receiving messages to prevent unwanted delivery.
Standard SNS topics provide best-effort delivery; FIFO topics offer ordered and exactly-once delivery.
Message filtering lets subscriptions receive only messages they care about, improving efficiency.
SNS supports cross-account and cross-region subscriptions, enabling scalable and distributed architectures.