SNS notification types (email, SMS, Lambda) in AWS - Time & Space Complexity
When sending notifications using SNS with different types like email, SMS, and Lambda, it's important to know how the number of notifications affects the work done.
We want to understand how the time to send notifications grows as we increase the number of messages.
Analyze the time complexity of the following operation sequence.
# Create SNS topic
aws sns create-topic --name MyTopic
# Subscribe email, SMS, and Lambda endpoints
aws sns subscribe --topic-arn arn:aws:sns:region:account:MyTopic --protocol email --notification-endpoint user@example.com
aws sns subscribe --topic-arn arn:aws:sns:region:account:MyTopic --protocol sms --notification-endpoint +1234567890
aws sns subscribe --topic-arn arn:aws:sns:region:account:MyTopic --protocol lambda --notification-endpoint arn:aws:lambda:region:account:function:MyFunction
# Publish message to topic
aws sns publish --topic-arn arn:aws:sns:region:account:MyTopic --message "Hello Subscribers"
This sequence sets up a topic with three types of subscribers and sends one message to all.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Publishing a message to the SNS topic.
- How many times: Once per message, but SNS fans out to all subscribers.
- Dominant operation: SNS sending notifications to each subscriber endpoint (email, SMS, Lambda).
Each message sent to the topic triggers SNS to send notifications to all subscribers.
| Input Size (n subscribers) | Approx. Notifications Sent |
|---|---|
| 10 | 10 notifications |
| 100 | 100 notifications |
| 1000 | 1000 notifications |
Pattern observation: The number of notifications grows directly with the number of subscribers.
Time Complexity: O(n)
This means the time to send notifications grows linearly with the number of subscribers.
[X] Wrong: "Sending one message to SNS means only one notification is sent regardless of subscribers."
[OK] Correct: SNS fans out the message to every subscriber, so the total notifications equal the number of subscribers.
Understanding how SNS scales with subscribers helps you design systems that handle many users efficiently and shows you can reason about cloud service behavior.
"What if we added message filtering so only some subscribers get notified? How would the time complexity change?"