0
0
AWScloud~5 mins

SNS notification types (email, SMS, Lambda) in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: SNS notification types (email, SMS, Lambda)
O(n)
Understanding Time 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.

Scenario Under Consideration

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 Repeating Operations

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).
How Execution Grows With Input

Each message sent to the topic triggers SNS to send notifications to all subscribers.

Input Size (n subscribers)Approx. Notifications Sent
1010 notifications
100100 notifications
10001000 notifications

Pattern observation: The number of notifications grows directly with the number of subscribers.

Final Time Complexity

Time Complexity: O(n)

This means the time to send notifications grows linearly with the number of subscribers.

Common Mistake

[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.

Interview Connect

Understanding how SNS scales with subscribers helps you design systems that handle many users efficiently and shows you can reason about cloud service behavior.

Self-Check

"What if we added message filtering so only some subscribers get notified? How would the time complexity change?"