- SNS has pub/sub model
- Event producer only sends message to one topic
- As many event receivers (subscriptions) as we want to listen
- Different from SQS where you have direct integration between listeners & senders.
- Retention: ❗ You have to process the data right away or it's lost
- Flow
- Event producer publish messages to a SNS topic
- ❗ Up to 100.000 topics (soft limit)
- Subscriptions listen a specific SNS topic
- ❗ Up to 10.000.000 subscriptions per topic (soft limit)
- Each subscriber get all the messages but can filter.
- Subscribers can be
- SQS
- HTTP/HTTPS (with delivery retries)
- Lambda
- Emails, SMS messages, Mobile Notifications
- High availability with managed replication to 3 AZ.
- Pay as you go pricing
- Integrations: SNS integrates with a lot of Amazon Services
- Some services can send data directly to SNS for notifications
- E.g. CloudWatch for alarms, Auto Scaling Groups notifications, Amazon S3 on bucket events CloudFormation (upon state changes => failed to build etc.) ...
- Publish types
- Topic Publish (within your AWS server - using the SDK)
- Create a topic
- Create a subscription (or many)
- Publish to the topic
- Direct Publish (for mobile apps SDK)
- Create a platform application
- Create a platform endpoint
- Publish to the platform endpoint
- Works with Google GCM, Apple APNS, Amazon ADM
- Topic Publish (within your AWS server - using the SDK)
- 📝Fan out (SNS -> SQS)
- Push once in SNS, receive in many SQS
- E.g. *Buying Service -> SNS Topic ->
- SQS Queue 1 (-> Fraud service)
- SQS Queue 2 (-> Shipping service)
- E.g. *Buying Service -> SNS Topic ->
- Good because:
- 💡 No data loss (in SNS you need to handle message right away)
- Ability to add receivers later
- SQS allows for delayed processing and retries of work
- May have many workers on one queue and one worker on the other queue
- In only SQS a message is not guaranteed to be delivered to all consumers
- Ability to add receivers later
- Push once in SNS, receive in many SQS