4.1.2. Amazon SNS for Notifications
First Principle: Amazon SNS provides a scalable and reliable pub/sub messaging service for developers, enabling efficient fan-out communication and immediate notifications to various endpoints.
SNS pushes messages from one publisher to many subscribers simultaneously ā the classic fan-out pattern. It's ideal for application-to-application (A2A) and application-to-person (A2P) communication.
- Publish/Subscribe (Pub/Sub) Model: Publishers send messages to a central topic, and all subscribers to that topic receive the message.
- Fan-out Capabilities: A single message published to an SNS topic can be delivered to multiple different types of subscribers simultaneously.
- Subscriber Types:
- AWS Lambda functions: For event processing.
- Amazon SQS queues: For reliable message delivery and decoupling.
- HTTP/S endpoints: For webhooks.
- Email, SMS, mobile push notifications.
- Message Filtering: Subscribers can filter messages received from a topic based on message attributes.
- Durability: Messages are stored durably across multiple Availability Zones.
Scenario: You're developing an image processing application. When a new image is uploaded and successfully processed, you need to notify several different downstream services (e.g., a database update, a search index rebuild) and also send an email notification to the user who uploaded the image.
ā ļø Exam Trap: SNS is push-based (subscribers receive immediately). SQS is pull-based (consumers poll for messages). If a question asks about notifying multiple services simultaneously, SNS is the answer. For buffering and decoupling, it's SQS.
