What is SNS and how it works?

What is SNS and how it works?

Amazon Simple notification service (SNS) is a web service that coordinates and manages the delivery or sending of messages to subscribing endpoints or clients. SNS provides topics for high-throughput, push-based, many-to-many messaging. It is a highly available, durable, secure, fully managed Pub/Sub messaging service that can be used to decouple microservices, distributed systems, and serverless applications. It helps to decouple the components of an application and allows them to scale independently and build loosely coupled systems which can also be coined as event-driven architecture (EDA).

How SNS works?

Amazon SNS sends notifications two ways, A2A and A2P. A2A provides high-throughput, push-based, many-to-many messaging between distributed systems, microservices, and event-driven serverless applications. These applications include Amazon Simple Queue Service (SQS), Amazon Kinesis Data Firehose, AWS Lambda, and other HTTP/S endpoints or to any other endpoint that supports the Simple Notification Service (SNS) protocol. A2P functionality lets you send messages to your customers with SMS texts, push notifications, and email. SNS also provides a simple, cost-effective, push-based mechanism to distribute notifications to large numbers of subscribers.

  1. SNS is a highly available, durable, secure, and scalable pub/sub messaging system with very low latency.

  2. SNS is a fully managed service, which means that AWS takes care of the infrastructure and maintenance of the service. You don't need to worry about the underlying infrastructure, such as the servers, operating systems, and network.

  3. SNS is a pub/sub messaging system, which means that the publisher does not need to know the subscribers. The publisher sends a message to the topic, and the message is delivered to all the subscribers of the topic.

  4. SNS is a highly available service, which means that it is designed to have a high degree of fault tolerance and to be able to recover from failures quickly, AWS guarantees 99.9% accuracy on SNS service.

  5. SNS is a durable service, which means that it can store messages for a long time. SNS is a secure service, which means that it uses encryption and authentication to protect your data.

  6. It is a scalable service, which means that it can handle a large number of requests and messages, and it provides high throughput.

sns-doc.png

SNS Topics

A topic is a logical access point and communication channel for a publisher to post a message that is immediately available for subscribers to consume. A topic is a container for messages that are published to the topic. Subscribers can be applications or end users. When a publisher sends a message to a topic, Amazon SNS delivers the message to each subscriber. A topic can have multiple subscribers, and each subscriber can have multiple protocols.

SNS Subscriptions

Subscriptions are the mechanism that delivers messages to subscribing endpoints or clients. A subscription is a communication channel to deliver notifications from a topic to subscribers. A subscription is an association between a topic and an endpoint. Subscriptions are uni-directional. A subscription can deliver notifications to one or more endpoints and to one or more protocols.

while creating a subscription, you can choose the protocol and endpoint. The protocol is the mechanism by which SNS delivers notifications to the endpoint. The endpoint is the location where the notification is sent.

Upon adding a subscription, SNS sends a confirmation message to the endpoint. The endpoint must confirm the subscription by sending a message back to SNS. The confirmation message is sent to the endpoint using the protocol that you specified when you created the subscription. For example, if you created a subscription with the HTTP protocol, the confirmation message is sent to the endpoint using the HTTP protocol to the endpoint with POST request. If you created a subscription with the email protocol, the confirmation message is sent to the endpoint using the email protocol. If you create a subscription with SQS as the protocol, the correct policy must be attached to the SQS queue.

SNS Message Delivery

SNS provides two types of message delivery, point-to-point, and publish-subscribe. Point-to-point delivery is a one-to-one communication between a sender and a receiver. Publish-subscribe delivery is a one-to-many communication between a sender and multiple receivers. SNS uses publish-subscribe delivery to send messages to multiple subscribers

SNS Message Delivery Guarantees

SNS provides two types of message delivery guarantees, at-least-once and exactly-once. At-least-once delivery is a message delivery guarantee that ensures that a message is delivered at least once. Exactly-once delivery is a message delivery guarantee that ensures that a message is delivered exactly once. SNS uses at-least-once delivery by default. SNS provides exactly-once delivery by using the SNS FIFO (first-in-first-out) topics.

SNS Message Delivery Order

SNS provides two types of message delivery orders, unordered and ordered. Unordered delivery is a message delivery order that ensures that a message is delivered in any order. Ordered delivery is a message delivery order that ensures that a message is delivered in the same order as it was sent. SNS uses unordered delivery by default. SNS provides ordered delivery by using the SNS FIFO (first-in-first-out) topics.

SNS Message Delivery Delay

SNS provides two types of message delivery delay, immediate and delayed. Immediate delivery is a message delivery delay that ensures that a message is delivered immediately. Delayed delivery is a message delivery delay that ensures that a message is delivered after a specified delay. SNS uses immediate delivery by default. SNS provides delayed delivery by using the SNS FIFO (first-in-first-out) topics.

SNS Message Delivery Retries

SNS provides two types of message delivery retries, automatic and manual. Automatic retries are the retries that are performed by SNS automatically. Manual retries are the retries that are performed by the subscriber. SNS uses automatic retries by default. SNS provides manual retries by using the SNS FIFO (first-in-first-out) topics.

SNS Message Delivery Failures

SNS provides two types of message delivery failures, permanent and transient. Permanent failures are the failures that are not recoverable. Transient failures are the failures that are recoverable. SNS uses permanent failures by default. SNS provides transient failures by using the SNS FIFO (first-in-first-out) topics.

SNS Dead Letter Queue

SNS provides two types of dead letter queues, standard, and FIFO. Standard dead letter queues are the dead letter queues that are used to store messages that failed to be delivered to the subscribers. FIFO dead letter queues are the dead letter queues that are used to store messages that failed to be delivered to the subscribers in the same order as they were sent. SNS uses standard dead letter queues by default. SNS provides FIFO dead letter queues by using the SNS FIFO (first-in-first-out) topics.

SNS Message Delivery Status

SNS provides two types of message delivery status, success (200 status code) and failure (400 status code). Success status is the status that is returned when a message is delivered successfully. Failure status is the status that is returned when a message is not delivered successfully. SNS uses success status by default. SNS provides failure status by using the SNS FIFO (first-in-first-out) topics.

Use Cases

  1. Integrate your applications with FIFO messaging
    • Deliver messages in a strictly ordered, first in, first out (FIFO) manner to maintain accuracy and consistency across independent applications.
  2. Securely encrypt notification message delivery

    • Encrypt messages with AWS Key Management Service (KMS), ensure traffic privacy with AWS PrivateLink, and control access with resource policies and tags.
  3. Capture and fan out events from over 60 AWS services

    • Fan out events across AWS categories, such as analytics, compute, containers, databases, IoT, machine learning (ML), security, and storage.
  4. Send SMS texts to customers across over 240 countries

    • Send SMS messages to customers in over 240 countries and territories, including the United States, Canada, Australia, and the United Kingdom.

    • Use worldwide SMS, with redundancy across providers. Set SMS origination identity with a sender ID, long code, short code, TFN, or 10DLC. Use Amazon Pinpoint to send SMS messages to customers in the United States, Canada, Australia, and the United Kingdom.

Pricing

Amazon SNS is a pay-as-you-go service. You pay only for the resources you use. There are no upfront costs or long-term commitments. You pay for the number of requests you make to Amazon SNS, the number of messages you publish to Amazon SNS topics, and the number of messages you receive from Amazon SNS subscriptions. You can also choose to pay for the number of messages that are delivered to your endpoints. For more information, see Amazon SNS Pricing.

SNS has also a free tier. It includes 1 million free requests, 100,000 free HTTP/S deliveries, and 1000 Email deliveries as of 24th Oct 2022. For more information, see Amazon SNS Free Tier.

Did you find this article valuable?

Support TheHTTP by becoming a sponsor. Any amount is appreciated!