AWS Simple Queue Service (SQS) vs Simple Notification Service (SNS)

A Comprehensive Comparison

Gabriel Varaljay
trendfingers
5 min readJul 1, 2023

--

As businesses increasingly embrace the shift towards cloud-based solutions, it’s critical to understand and leverage the tools available to manage data and communication processes effectively. Two standout services within the Amazon Web Services (AWS) suite are the Simple Queue Service (SQS) and the Simple Notification Service (SNS). Though they share similarities, their differences define distinct use cases. This article delves into the features, differences, and suitable scenarios for both services.

Midjourney prompt: Cinematic still, people dressed in white are queuing in the most surreal sci-fi setting, a lot of reflections and mirrors, minimal, red and blue color scheme, dark and moody, Canon 5D Mark IV 35mm, wide angle — ar 3:2 — q 2 — s 250

What is Amazon SQS?

Amazon SQS, or Simple Queue Service, is a fully managed message queuing service that facilitates the decoupling and scaling of microservices, distributed systems, and serverless applications. SQS enables you to transmit any volume of data, at any level of throughput, without losing messages or requiring other services to be always available.

There are two types of SQS queues: standard and FIFO (First-In-First-Out).

Standard queues offer maximum throughput and at least once delivery. They also allow occasional out-of-order delivery of messages.

Conversely, FIFO queues ensure messages are processed in the exact order they are sent, and each message is delivered once and remains available until the consumer processes and deletes it.

What is Amazon SNS?

Amazon SNS, or Simple Notification Service, is a fully managed publish/subscribe messaging service. It is designed to decouple microservices, distributed systems, and serverless applications, similar to SQS.

With SNS, you can fan out push messages to many subscribers, including distributed systems, services, and mobile devices. It allows you to send individual messages to a specific topic, a logical access point and communication channel, to multiple subscribers. The subscribers could be SQS queues, AWS Lambda functions, HTTP(S) endpoints, email addresses, or mobile devices.

Differences Between Amazon SQS and SNS

The core distinction between SQS and SNS lies in their architectural style and communication model.

SQS is a pull-based (or polling) system, which means the consumer must actively check for and retrieve messages from the queue. It is ideal when you want to process messages in an exact sequence or if you need to ensure a message is processed only once.

What is pull-based system?

A pull-based system, also known as a polling system in the realm of computing, is a model where a consumer or client initiates a request for information or data. This is in contrast to a push-based system, where data or information is sent to a client without a specific request being made.

In a pull-based system, the client actively requests or ‘pulls’ data from a server when it requires it. The server sends information once it receives an explicit request from the client. In essence, control lies with the client in determining when it needs data from the server.

An everyday example of a pull system is an email client retrieving, or ‘pulling’, emails from a server. The server does not push the emails to the client. Instead, the client must initiate the process by clicking a ‘refresh’ button to check for new emails.

This model allows for greater control by the client over data traffic, reducing unwanted or unneeded data transfer. It also can reduce server load, as data is only sent upon request. However, it can delay receiving data as the server must wait for a request from the client before it can send data.

Pull-based systems, such as Amazon’s Simple Queue Service (SQS), are used extensively in scenarios where precise control over when and how data is received is paramount, such as processing messages in an exact sequence or when it is crucial to ensure a message is processed only once.

On the other hand, SNS utilises a push model. Once a message is published to a topic, SNS pushes the message to all subscribers. It is suitable to send identical messages to many recipients at once.

What is push-based system?

In information technology, a push-based system is a communication model where data is automatically “pushed” or sent to a client (like a user or a server) without the client needing to request it. This stands in contrast to a pull-based system where the client must request, or “pull”, the data before it is sent.

In a push-based system, once new content is available, it is sent out to the clients without waiting for them to ask. This approach has the advantage of real-time or near-real-time distribution of information, ensuring clients have immediate access to the most recent data.

Examples of push-based systems include email notifications (where you receive an email without asking for it) and app notifications (where an app notifies you of new messages, updates, etc., without needing to check the app).

The term “push” in this context is metaphorical: the information is pushed out to the client in a similar way that one might push a physical object toward another person without waiting for them to reach out and take it. It’s a proactive distribution of information, instead of a reactive or on-demand one, as in a pull-based system.

Another critical difference is the message delivery guarantee. While SQS guarantees that a message will be delivered at least once, SNS offers a similar promise but also provides the ability to ensure that the message delivery occurs at least once by setting up a delivery policy.

Use Case Scenarios

Amazon SQS

SQS is ideal for building a decoupled microservices architecture where multiple services must communicate asynchronously. If you have a task involving multiple steps and want to ensure each step is successfully completed before the next one starts, an SQS FIFO queue would be the optimal solution.

For instance, an e-commerce website may need to process orders that involve several steps: payment processing, inventory updating, delivery scheduling, etc. Each step can be a message in the SQS queue, and they need to be processed in sequence.

Amazon SNS

SNS shines when you need a one-to-many notification service to fan out messages to multiple subscribers. An apt example would be a weather forecasting system that needs to alert various departments (local authorities, media, schools, etc.) about upcoming weather conditions. Each department can subscribe to the SNS topic and receive weather updates simultaneously.

Moreover, SNS is a good fit for mobile push notifications. Mobile applications can subscribe to SNS topics and receive notifications directly, promoting real-time user engagement.

Conclusion

In essence, both SQS and SNS are powerful services AWS provides to handle different messaging and notification needs. SQS is particularly suited for handling sequential and at-least-once message processing, while SNS excels in sending identical messages to multiple recipients. Businesses can use these tools to build robust, scalable, and efficient applications by understanding their unique features and capabilities.

--

--

Gabriel Varaljay
trendfingers

Multi-Cloud & DevOps | AWS | Microsoft Azure | Google Cloud | Oracle Cloud | Linux | Terraform | digital problem solver