What is Amazon SNS (Simple Notification Service)?

Amazon SNS (Simple Notification Service) is a managed messaging service offered by AWS. You can use Amazon SNS to send messages from application to application or from application to person. You can use Amazon SNS in different modes i.e. Pub/Sub, SMS, Email or mobile notifications.

Two Types of Communication Methods

Amazon SNS can be used for two different types of communication. These are:

  • A2A (Application To Application): This type of communication is common in distributed systems where you can de-couple the systems and one will only perform the task when it receives a message from another one. The most widely used mode for this is Pub/Sub. Amazon SNS allows you to create a publisher topic and all the subscribers will receive the message broadcasted to that topic.
  • A2P (Application To Person): This type of communication is used when an application notifies the user about something which happened in the app context. For example a notification regarding any task which is pending and is waiting on the user to reply. This also used to send OTP (one-time-password) to the user wherever required. The SMS and the Mobile Push notifications are examples of A2P communication.

Publish/Subscriber Model

There are two components in a system:

  • Publisher: A service that can broadcast out messages to its subscribers.
  • Subscriber: Any service that wishes to receive the messages broadcasted by the publisher.

If a service wishes to subscribe to a publisher, it needs to notify the publisher that it wants to receive its broadcasts along with where it wishes to receive i.e. the endpoint. It can be HTTP endpoint, SQS or lambda function.
In the above diagram, the publisher is sending a message to Amazon SNS topic via the service and all the subscribers will receive the message but the mode or endpoint using which they have subscribed is different.

Benefits of Amazon SNS

Some of the benefits of Amazon SNS are:

  • De-couple Applications: Amazon SNS allows you to de-couple the application by acting as a notifier between the two. Once a job is done by an application it can safely broadcast a message to all the subscribers to perform any action required after the event is complete.
  • Scalable: If you are using A2P communication, you will be able to broadcast the message to millions of users without any issues. Amazon SNS allows you to push the mobile notifications to all providers using a single endpoint. In terms of using the A2A communication, Amazon SNS can scale as your application grows and allows you to create a robust system.
  • Reliable: Many strategies make Amazon SNS reliable. It automatically tries to resend the messages which are not delivered. You can attach a DLQ (Dead Letter Queue) to save the messages if they fail to deliver after the retry. Amazon Kinesis Firehose allows you to stream the messages to a durable store like Amazon S3 and can be utilised in future processing.
  • Amazon SNS FIFO ensures the messages are delivered in the same order as they are published on the Amazon SNS. Amazon SNS works with the Amazon SQS FIFO.

This is a quick introduction to Amazon SNS. I will cover some of the topics like sending messages using javascript and also using Amazon SNS in various architectural patterns etc.