Difference Between SQS vs SNS

Technology Crunch
4 min readDec 15, 2022

--

An introduction to AWS SNS (Simple Notification Service)

Amazon SNS is a fast, flexible, fully managed push notification service that lets you send individual messages or to bulk messages to large numbers of recipients. Amazon SNS makes it simple and cost effective to send push notifications to mobile device users, email recipients or even send messages to other distributed services.

As one of the earliest managed services launched on AWS, SNS is a distributed publish/subscribe solution used for application-to-application (A2A) and application-to-person (A2P) communication.

SNS is a distributed publish-subscribe system. Messages are pushed to subscribers as and when they are sent by publishers to SNS

SNS topics are used to enable communication: producers publish messages to topics, and consumers subscribe to these topics to receive messages. You can deliver messages to various types of subscribers, such as AWS SQS queues, AWS Lambda functions, and HTTP endpoints. You can also use SNS to send SMS messages, email, and push notifications to end-user devices.

With Amazon SNS, you can send push notifications to Apple, Google, Fire OS, and Windows devices , as well as to Android devices in China with Baidu Cloud Push. You can use SNS to send SMS messages to mobile device

There are two types of topics:

  • Standard topics. They offer maximum throughput, best-effort ordering, and best-effort deduplication (messages may be delivered more than once).
  • FIFO topics. Provide strict ordering and deduplication. The downside is that you can use FIFO topics to send events only to SQS queues (no other type of consumer is supported).

An introduction to AWS SQS (Simple Queue Service)

Amazon SQS is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications.

AWS SQS is a distributed, managed queueing service used for communication between applications, microservices, and distributed systems.

SQS is distributed queuing system. Messages are not pushed to receivers. Receivers have to poll SQS to receive messages. Messages can be stored in SQS for short duration of time (max 14 days).

As with most messaging middleware, SQS consists of three major components:

  • Producers (components that send messages to the queue).
  • Queue (which stores messages).
  • Consumers (other components that receive messages from the queue).

Messages can’t be received by multiple receivers at the same time. Any one receiver can receive a message, process and delete it. Other receivers do not receive the same message later.

There are two types of queues:

  • Standard queues. They offer maximum throughput, best-effort ordering, and at-least-once delivery.
  • FIFO queues. Designed to guarantee that messages are processed exactly once, in the same order that they are sent.

What is the difference between AWS SNS and SQS?

We will now look at the main differences between AWS SNS and SQS. We will focus on two main areas: feature differences and use cases.

AWS SNS vs SQS key feature differences

There are some key distinctions between SNS and SQS:

  1. SNS supports A2A and A2P communication, while SQS supports only A2A communication.
  2. Entity Type
    SQS : Queue (similar to JMS, MSMQ).
    SNS : Topic-Subscriber (Pub/Sub system).
  3. Persistence
    SQS : Messages are persisted for some duration is no consumer available. The retention period value is from 1 minute to 14 days. The default is 4 days.
    SNS : No persistence. Whichever consumer is present at the time of message arrival, get the message and the message is deleted. If no consumers available then the message is lost.
  4. In SQS the message delivery is guaranteed but in SNS it is not.
  5. With SQS, messages are delivered through a long polling (pull) mechanism, while SNS uses a push mechanism to immediately deliver messages to subscribed endpoints.
  6. SNS is typically used for applications that need realtime notifications, while SQS is more suited for message processing use cases.
  7. Consumer Type
    SQS : All the consumers are supposed to be identical and hence process the messages in exact same way.
    SNS : All the consumers are (supposed to be) processing the messages in different ways.

What AWS SNS and SQS are used for

Individually, Amazon SQS and SNS are used for different use cases. You can, however, use them together in some scenarios.

WHEN TO USE AWS SNS

You can use SNS for a variety of purposes, including:

  • Sending email, SMS, and push notifications to end-users in realtime. Note that you can send push notifications to Apple, Google, Fire OS, and Windows devices.
  • Broadcasting messages to multiple subscribers (for example, fanning out the same push notifications to all users of your app).
  • Workflow systems. For example, you can use SNS to pass events between distributed apps, or to update records in various business systems (e.g., inventory changes).
  • Real-time alerts and monitoring applications.

WHEN TO USE AWS SQS

SQS is helpful for:

  • Asynchronous processing workflows.
  • Processing messages in parallel (by using multiple SQS queues).
  • Decoupling and scaling microservices, distributed systems, and serverless applications.
  • Sending, storing, and receiving events with reliable messaging guarantees (ordering & exactly-once processing).

--

--