Full Stack • Java • System Design • Cloud • AI Engineering

Amazon SNS (Simple Notification Service)

Learn Amazon SNS with Spring Boot. Understand Publish-Subscribe messaging, Topics, Subscribers, Fan-out Pattern, Message Filtering, Delivery Retries, FIFO Topics, Amazon SQS integration, AWS Lambda integration, and enterprise event-driven architectures.


Introduction

Modern enterprise applications rarely have only one consumer for business events.

Imagine a customer places an order in an e-commerce application.

Immediately after the order is created, multiple systems need to react.

Examples:

  • Payment Service
  • Inventory Service
  • Email Service
  • SMS Notification
  • Analytics Platform
  • Fraud Detection
  • Recommendation Engine
  • Audit Service

Should the Order Service call every service individually?

No.

Doing so creates:

  • Tight Coupling
  • Complex Code
  • High Latency
  • Difficult Maintenance
  • Poor Scalability

Instead, enterprise systems use Amazon SNS (Simple Notification Service).

Amazon SNS follows the Publish-Subscribe (Pub/Sub) messaging model, where one published message can be delivered to many subscribers simultaneously.


What is Amazon SNS?

Amazon SNS is a fully managed Publish-Subscribe messaging service provided by AWS.

A producer publishes a message to an SNS Topic.

SNS immediately delivers a copy of the message to every subscribed endpoint.

AWS manages:

  • Infrastructure
  • Scaling
  • Availability
  • Delivery
  • Retry Mechanisms

Developers only focus on business events.


Why Amazon SNS?

Imagine a banking application.

Customer completes a payment.

Several business processes must execute:

  • Send SMS
  • Send Email
  • Update Analytics
  • Notify Fraud Service
  • Notify Audit System
  • Trigger Cashback Service

Instead of directly calling every service,

the Payment Service publishes one event to SNS.

SNS distributes the event automatically.


High-Level Architecture

flowchart LR

PRODUCER[Payment Service]

PRODUCER --> TOPIC[(Amazon SNS Topic)]

TOPIC --> EMAIL[Email Service]

TOPIC --> SMS[SMS Service]

TOPIC --> ANALYTICS[Analytics]

TOPIC --> FRAUD[Fraud Detection]

One published event reaches multiple subscribers.


Core Components

Amazon SNS consists of:

  • Producer
  • Topic
  • Subscription
  • Subscriber
  • Message
  • Filter Policy
  • Delivery Policy
  • Retry Policy

Each component contributes to reliable event distribution.


Producer

The Producer publishes messages.

Examples:

  • Order Service
  • Payment Service
  • Customer Service
  • Inventory Service

Example:


Order Created

↓

SNS Topic

The producer has no knowledge of subscribers.


Topic

A Topic is the communication channel.

Characteristics:

  • One Topic
  • Many Subscribers
  • Automatic Fan-out
  • Highly Available
  • Fully Managed

Messages are never sent directly to subscribers.

Everything goes through the Topic.


Subscriber

Subscribers receive messages.

Examples:

  • Amazon SQS
  • AWS Lambda
  • HTTP Endpoint
  • Email
  • SMS
  • Mobile Push Notification

Every subscriber receives its own copy of the event.


Publish-Subscribe Model

flowchart LR
    PUB["Publisher"]

    TOPIC["SNS Topic"]

    EMAIL["Email Subscriber"]
    SMS["SMS Subscriber"]
    LAMBDA["Lambda Subscriber"]
    QUEUE["SQS Queue"]

    PUB --> TOPIC

    TOPIC --> EMAIL
    TOPIC --> SMS
    TOPIC --> LAMBDA
    TOPIC --> QUEUE

One message,

many independent consumers.


Message Flow

sequenceDiagram

participant Producer

participant SNS

participant Subscriber

Producer->>SNS: Publish Event

SNS-->>Producer: Acknowledged

SNS->>Subscriber: Deliver Event

SNS pushes messages to subscribers.


Fan-out Pattern

SNS implements the Fan-out Pattern.

flowchart TD
    EVENT["Order Created"]

    TOPIC["SNS Topic"]

    INVENTORY["Inventory Service"]
    BILLING["Billing Service"]
    EMAIL["Email Service"]
    ANALYTICS["Analytics Service"]
    AUDIT["Audit Service"]

    EVENT --> TOPIC

    TOPIC --> INVENTORY
    TOPIC --> BILLING
    TOPIC --> EMAIL
    TOPIC --> ANALYTICS
    TOPIC --> AUDIT

Each service processes the event independently.


Topic Lifecycle

flowchart LR
    CREATE["Create Topic"]

    SUB["Subscribe"]

    PUB["Publish"]

    DELIVER["Deliver Message"]

    RETRY["Retry Mechanism"]

    DONE["Complete"]

    CREATE --> SUB --> PUB --> DELIVER --> RETRY --> DONE

SNS manages delivery automatically.


Supported Subscriber Types

SNS can deliver messages to:

  • Amazon SQS
  • AWS Lambda
  • HTTP
  • HTTPS
  • Email
  • SMS
  • Mobile Push
  • Firehose (via integration patterns)

This flexibility makes SNS suitable for many architectures.


SNS + Amazon SQS

A common enterprise pattern combines SNS and SQS.

flowchart LR
    PRODUCER["Producer Service"]

    SNS["Amazon SNS Topic"]

    SQS_A["SQS Queue A"]
    SQS_B["SQS Queue B"]
    SQS_C["SQS Queue C"]

    SERVICE_A["Service A"]
    SERVICE_B["Service B"]
    SERVICE_C["Service C"]

    PRODUCER --> SNS

    SNS --> SQS_A
    SNS --> SQS_B
    SNS --> SQS_C

    SQS_A --> SERVICE_A
    SQS_B --> SERVICE_B
    SQS_C --> SERVICE_C

Benefits:

  • Loose Coupling
  • Independent Scaling
  • Retry Support
  • Failure Isolation

SNS + AWS Lambda

SNS can invoke Lambda functions directly.

flowchart LR
    PRODUCER["Producer Service"]

    SNS["Amazon SNS Topic"]

    LAMBDA_A["Lambda Function A"]
    LAMBDA_B["Lambda Function B"]
    LAMBDA_C["Lambda Function C"]

    PRODUCER --> SNS

    SNS --> LAMBDA_A
    SNS --> LAMBDA_B
    SNS --> LAMBDA_C

Ideal for serverless architectures.


SNS + Email


Application

↓

SNS

↓

Email

↓

Customer

Useful for alerts and notifications.


SNS + SMS


Payment Success

↓

SNS

↓

SMS

↓

Customer

Supports transactional notifications.


Message Filtering

Not every subscriber needs every message.

SNS supports Filter Policies.

Example:


Event Type

↓

Payment

↓

Payment Queue

Order

↓

Order Queue

Filtering reduces unnecessary processing.


FIFO Topics

Amazon SNS supports FIFO Topics.

Features:

  • Ordered Delivery
  • Deduplication
  • Exactly-Once Ordering (within supported constraints)

Useful for:

  • Banking
  • Payments
  • Financial Workflows

Standard Topics

Standard Topics provide:

  • High Throughput
  • Best-Effort Ordering
  • High Scalability

Suitable for:

  • Notifications
  • Analytics
  • Event Broadcasting

Standard vs FIFO Topics

Feature Standard Topic FIFO Topic
Ordering Best Effort Strict
Throughput Very High High
Deduplication No Yes
Best For Notifications Financial Systems

Retry Mechanism

SNS retries failed deliveries.

flowchart LR

SNS

-->

Subscriber

Subscriber --> Success

Subscriber --> Retry

Retry --> Failure

Retry behavior depends on subscriber type.


Dead Letter Queue

Failed deliveries can be redirected.

flowchart LR
    TOPIC["SNS Topic"]

    SUBSCRIBER["Subscriber Service"]

    PROCESS["Processing Logic"]

    FAILURE["Failure Handler"]

    DLQ["Dead Letter Queue (SQS)"]

    TOPIC --> SUBSCRIBER --> PROCESS

    PROCESS --> FAILURE --> DLQ

DLQs improve reliability and troubleshooting.


Security

SNS supports:

  • IAM Policies
  • Topic Policies
  • AWS KMS Encryption
  • HTTPS
  • VPC Endpoints (through integrated services)

Sensitive messages should always be encrypted.


Monitoring

Monitor:

  • Published Messages
  • Delivered Messages
  • Failed Deliveries
  • Retry Count
  • Subscriber Health
  • DLQ Messages

Tools:

  • Amazon CloudWatch
  • CloudTrail
  • AWS X-Ray (integrated architectures)
  • Grafana
  • Datadog

Spring Boot Integration

Spring Boot integrates with SNS using:

  • Spring Cloud AWS
  • AWS SDK for Java

Applications can:

  • Publish Events
  • Subscribe through SQS or Lambda integrations
  • Build event-driven microservices

Enterprise Architecture

flowchart TD

CLIENT[Client]

CLIENT --> ORDER[Order Service]

ORDER --> SNS[(Amazon SNS)]

SNS --> PAYMENT[Payment Service]

SNS --> INVENTORY[Inventory Service]

SNS --> EMAIL[Notification Service]

SNS --> ANALYTICS[Analytics]

SNS --> AUDIT[Audit Service]

SNS broadcasts business events across the enterprise.


Banking Example

Payment Completed


Payment Event

↓

SNS

↓

SMS

↓

Email

↓

Fraud Detection

↓

Audit

Every system reacts independently.


Insurance Example

Claim Approved


Claim Approved

↓

SNS

↓

Billing

↓

Customer Notification

↓

Analytics

Healthcare Example

Patient Registered


Patient

↓

SNS

↓

Laboratory

↓

Billing

↓

Appointments

Retail Example

Order Created


Order

↓

SNS

↓

Warehouse

↓

Shipping

↓

Email

↓

Recommendation Engine

Advantages

  • Fully Managed
  • Automatic Fan-out
  • High Availability
  • Loose Coupling
  • Event Broadcasting
  • AWS Native
  • Easy Integration
  • Scalable

Challenges

  • Duplicate processing in Standard Topics
  • Subscriber management
  • Event ordering limitations
  • Monitoring many subscribers
  • Message filtering complexity

Amazon SNS vs Amazon SQS

Feature Amazon SNS Amazon SQS
Communication Model Publish-Subscribe Queue
Consumers Multiple Usually One per Message
Message Distribution Fan-out Task Processing
Push/Pull Push Pull
Best For Event Broadcasting Background Processing

Amazon SNS vs Apache Kafka

Feature Amazon SNS Apache Kafka
Primary Use Notifications Event Streaming
Replay No Yes
Storage Temporary Delivery Persistent Log
Consumer Groups No Yes
Event History No Yes

Best Practices

  • Use SNS for event broadcasting.
  • Use SQS subscriptions for reliable processing.
  • Apply Filter Policies.
  • Configure Dead Letter Queues.
  • Encrypt sensitive topics.
  • Monitor failed deliveries.
  • Design idempotent consumers.
  • Separate business domains into different topics.
  • Avoid publishing oversized messages.
  • Use FIFO Topics when ordering matters.

Common Mistakes

❌ Using SNS for long-term event storage.

❌ Ignoring duplicate event handling.

❌ No DLQ.

❌ Broadcasting unnecessary events.

❌ Missing monitoring.

❌ Hardcoding subscriber endpoints.


Enterprise Use Cases

Banking

  • Payment Events
  • Fraud Alerts
  • Customer Notifications

Insurance

  • Claim Events
  • Policy Notifications
  • Billing Updates

Healthcare

  • Appointment Notifications
  • Patient Registration
  • Prescription Alerts

Retail

  • Order Events
  • Promotions
  • Shipping Notifications

Logistics

  • Shipment Events
  • Delivery Notifications
  • Tracking Updates

Interview Questions

  1. What is Amazon SNS?
  2. What is the Publish-Subscribe model?
  3. What is a Topic?
  4. What subscriber types does SNS support?
  5. What is the Fan-out Pattern?
  6. What is the difference between SNS and SQS?
  7. What are Filter Policies?
  8. What is an SNS FIFO Topic?
  9. How does SNS integrate with Lambda?
  10. Why combine SNS with SQS?

Summary

Amazon SNS is a fully managed Publish-Subscribe messaging service that enables one application event to be delivered to many independent subscribers.

Its architecture includes:

  • Producers
  • Topics
  • Subscribers
  • Fan-out Messaging
  • Filter Policies
  • Retry Mechanisms
  • Dead Letter Queues
  • AWS Integrations

SNS is ideal for broadcasting business events, sending notifications, and building loosely coupled event-driven systems.

When combined with Spring Boot, Amazon SQS, AWS Lambda, EventBridge, and other AWS services, SNS forms the backbone of scalable cloud-native architectures used in banking, insurance, healthcare, retail, logistics, SaaS, and enterprise applications.