Azure  

Amazon Simple Notification Service (SNS)

Amazon SNS

Amazon SNS is a fully managed messaging service in Amazon Web Services that enables publish/subscribe (pub/sub) communication between applications, services, and users.

It is mainly used to send notifications or messages to multiple subscribers simultaneously.

1. What Problem SNS Solves

In distributed systems, sometimes one service needs to notify many services at the same time.

Without SNS:

Service A → Service B
Service A → Service C
Service A → Service D

This creates tight coupling and complexity.

With SNS:

Service A → SNS Topic → Multiple Subscribers

SNS sends the message to all subscribed services automatically.

2. Core Components of SNS

1. Publisher

The service that sends a message to SNS.

Examples:

  • Applications

  • AWS services

  • Microservices

2. Topic

A communication channel where messages are sent.

Example topic:

OrderUpdatesTopic

Publishers send messages to the topic, not directly to subscribers.

3. Subscribers

Endpoints that receive the message.

Supported subscriber types:

  • Email

  • SMS

  • HTTP/HTTPS endpoints

  • AWS Lambda

  • SQS queues

  • Mobile push notifications

3. How SNS Works (Step-by-Step)

  • A publisher sends a message to an SNS topic.

  • SNS receives the message.

  • SNS pushes the message to all subscribers.

Flow:

Publisher

SNS Topic
↓ ↓ ↓
Email SQS Lambda

This is called fan-out messaging.

4. Example Message

Example message sent to a topic:

{"event": "order_created","order_id": 10045}

SNS sends this message to all subscribers.

5. SNS Message Delivery Types

Push-Based Messaging

SNS pushes messages automatically to subscribers.

Example:

SNS → Email notification
SNS → Lambda trigger
SNS → HTTP endpoint

This is different from queue systems that require polling.

6. Common SNS Use Cases

1. Application Alerts

Example:

Server CPU > 90%
CloudWatch → SNS → Email/SMS alert

Monitoring alerts sent to administrators.

Works with:
Amazon CloudWatch

2. Event Notifications

Example:

File uploaded to S3

SNS notification

Multiple services triggered

Uses:
Amazon S3

3. Microservices Communication

SNS helps multiple services react to an event.

Example:

Order created

SNS Topic
↓ ↓ ↓
Inventory Service
Billing Service
Email Service

4. Mobile Notifications

SNS can send push notifications to mobile apps.

Supported platforms:

  • Android

  • iOS

  • Fire OS

7. SNS Fan-Out Architecture

SNS is often used with Amazon Simple Queue Service (SQS).

Example:

Application

SNS Topic
↓ ↓ ↓
SQS1 SQS2 SQS3

Each queue processes messages independently.

Example:

  • Queue 1 → Order processing

  • Queue 2 → Analytics

  • Queue 3 → Notifications

8. Security Features

SNS supports:

  • IAM policies using AWS Identity and Access Management

  • Encryption with AWS KMS

  • HTTPS secure endpoints

  • Access control policies

9. SNS vs SQS (Quick Comparison)

FeatureSNSSQS
Communication ModelPublish/SubscribeMessage Queue
Message DeliveryPushPull (polling)
Message ConsumersMultiple subscribersUsually one consumer
Use CaseNotificationsBackground processing

Example:

SNS → notify multiple services
SQS → process tasks asynchronously

10. Real-World Example

E-commerce Order Event

When a user places an order:

Order Service

SNS Topic
↓ ↓ ↓
Email Service
Shipping Service
Analytics Service

Benefits:

  • All services get notified instantly

  • Loose coupling

  • Scalable architecture

11. Simple Architecture Diagram

Publisher (Application)

SNS Topic
↓ ↓ ↓
Email SQS Lambda

✅ One-line interview definition:

Amazon SNS is a fully managed publish/subscribe messaging service used to send notifications or messages to multiple subscribers simultaneously.