Publish/Subscribe (pub/sub) messaging enables asynchronous communication when sending applications broadcast messages to multiple receiving applications with little or no knowledge about recipients.
Key Components :
Publisher : Sending application that publishes messages to topics
Subscriber : Receiving applications that subscribe to topics to receive messages
Topic : Interim destination that broadcasts messages to subscribers
Push Mechanism : Eliminates need for periodic polling, messages pushed immediately
Recipients subscribe to topics of interest
Publisher publishes message to topic
Topic automatically pushes messages to all subscribers asynchronously
Unlike message queues that store messages until retrieved, topics transfer messages with minimal queueing and push immediately to all subscribers.
Amazon SNS is a fully managed pub/sub messaging service that:
Sets up, operates, and sends notifications from the cloud
Follows push mechanism for notification delivery
Meets demands of largest applications with unlimited message publishing
Provides no maintenance overhead with pay-as-you-go pricing
Topic Creation : Unique names identify SNS endpoints for publishers and subscribers
Policy Control : Restricts who can publish or subscribe to topics
Universal Delivery : All subscribers receive same messages from subscribed topics
Secure Communication : TLS support for publishers and subscribers
Durable Storage : Multiple copies stored across Availability Zones during processing
No Persistence : Messages deleted after publishing to subscribers
Amazon SNS supports multiple destination types for message delivery:
Email Destination
Messages sent to registered email addresses in text or JSON format
Mobile SMS
Short Message Service (SMS) text messages to registered phone numbers
Mobile Push
Native push notifications to mobile device endpoints
HTTP/HTTPS Endpoints
Messages sent to URL addresses via HTTP POST requests
Advanced Integration Subscribers :
AWS Lambda Function : Invoke custom business logic
SQS Queue : Store messages for later processing by receiver applications
Amazon Kinesis Data Firehose : Deliver to storage and analytics endpoints
Application and System Alerts : Immediate notification for events like Auto Scaling group changes
Push Email and Text Messaging : Targeted news headlines to subscribers via email or SMS
Mobile Push Notifications : App update notifications with download links
Image Processing Architecture : Mobile client uploads image for conversion into three different sizes
Flow Process :
Mobile app uploads image to S3 bucket
S3 event notification publishes message to SNS topic with object URL
Topic fans out simultaneously to three SQS queues:
Generate thumbnail queue
Size for mobile queue
Size for web queue
Each queue monitored by separate Auto Scaling applications
Applications perform independent resizing and store results in converted images bucket
This architecture enables parallel asynchronous processing with automatic scaling based on workload.
Single Message : Each notification contains one published message
No Recall : Successfully delivered messages cannot be recalled
Topic Types :
Standard : Best-effort ordering, potential out-of-order delivery
FIFO : Strict message ordering preservation
Retry Behavior Control : Amazon SNS defines delivery policies for each protocol
Controls retry patterns when subscribed endpoints become unavailable
HTTP/HTTPS Exception : Only endpoints with customizable delivery policies
Dead Letter Queue : Attaches to subscription when delivery policy exhausted
Message Discard : Without DLQ, messages discarded after policy exhaustion
Messaging Model : Publisher-Subscriber
Distribution : One to many
Delivery : Push (passive)
Persistence : No message persistence
Messaging Model : Producer-Consumer
Distribution : One to one
Delivery : Pull (active)
Persistence : Messages persist until deleted
SNS Publishers don’t necessarily know subscribers; SQS Producers know message consumers
SNS requires subscribers available at publication time; SQS consumers can be offline when messages sent
SNS messages deleted after publishing; SQS messages persist until consumer deletion or retention limit
Combined Architecture Benefits : Using SNS with SQS provides highly available message routing for effective distribution to decoupled application functions.
Fanout Pattern : SNS topic replicates and pushes messages to multiple SQS queues, HTTP endpoints, or email addresses for parallel processing.
This combination leverages the strengths of both services - SNS for broadcast distribution and SQS for reliable message queuing and processing.
Pub/Sub Service