Certifications / Cloud

AWS SNS vs SQS: What Service Should You Choose?

AWS-SNS-vs-SQS-Blog
Follow us
Published on August 17, 2023

AWS SNS and AWS SQS sound similar, so it’s understandable when someone new to AWS gets the two confused. Both SNS and SQS fully managed distributed messaging tools, but SNS is a “push” technology, while services are configured to “pull” from SQS. Additionally, they have differing features and capabilities. 

Here we break down Amazon SNS and Amazon SQS so you know which to choose for your message delivery system. 

What is Amazon SNS?

Amazon Simple Notification Service (SNS) is a message delivery service that allows for instant notifications from publishers to subscribers. 

Amazon SNS Benefits

The key benefit of Amazon SNS is in the name: It’s simple. There’s no need for complex, dedicated messaging solutions with expensive software licenses. AWS claims that its notification service is also reliable, scalable, flexible, and secure. With pay-as-you-go pricing, the small per-request charges for SNS make it easy on the IT budget. 

Amazon SNS Features

SNS, like its SQS counterpart, is basically a communication channel. You can configure a first in, first out (FIFO) topic, which is targeted to SQS subscriptions. Standard SNS topics can be sent to multiple endpoints, such as email, SMS, HTTP, or Lambda.

In fact, you can use SNS to send an individual message simultaneously in a “fanout” fashion to several receivers at once. 

Amazon SNS Examples

Publishers and subscribers in SNS are also referred to as producers and consumers. It is unidirectional traffic with senders and receivers. One common use case of SNS is to send messages to mobile phones through the short message service (SMS), also known as cell phone texts. Messages can be sent for all kinds of reasons, such as the confirmation of a purchase, notification of a required action, or as some sort of reminder.

Additionally, you could set up an SNS message to notify a user when a CloudWatch threshold has been reached or when a change has been made to your AWS compute services. SNS may come into play when you want to email users to inform them a service has been created. You can also use SNS when you want to trigger an application to execute based on the results of another application. 

To learn more, check out How to Create an Amazon SNS Topic with PowerShell

What is Amazon SQS?

Amazon Simple Queue Service (SQS) is a message delivery service that allows you to move data between distributed and decoupled software components. 

Amazon SQS Benefits

Loose coupling of software is one of the fundamental principles of cloud computing. One of the ways AWS has achieved that is through its powerful SQS messaging. SQS has benefits similar to those described above regarding SNS, but it has some added complexity. SQS allows for messages to be resent, and you can retain messages for up to 14 days. SQS will buffer and scale requests to handle spikes in the workload. 

Amazon SQS Features

Queue is the middle name of SQS. While SNS messages are sent once and you’re done, SQS supports dead-letter queues (DLQ). If a message isn’t processed properly, it can be sent to the dead-letter queue and moved back to the source queue for reprocessing. You can postpone messages using delay queues. You can create temporary queues dedicated to particular processes. Short polling polls the queue, even if it’s empty, with the chance of incurring unnecessary costs. Long polling only polls the queue when a message arrives.

Amazon SQS Examples

With SQS, you can send and receive messages, but you can also store and manage them. SQS is part of the AWS toolkit for the NASA Image and Video Library. Through decoupling, NASA is able to process incoming jobs using SQS queuing capabilities. They are not limited to an undifferentiated message pipeline.

You can use SQS for asynchronous messages or parallel processing. A message may remain in the queue for days until polled and processed by a particular application. By offloading messages to a queue, multiple services can poll messages in parallel. For instance, you can use Lambda to process messages from an SQS queue with multiple functions.

Confused about Lambda? Read AWS Lambda vs EC2: Which to Use and When | CBT Nuggets.

Combining AWS SNS with AWS SQS

The power of AWS SNS and AWS SQS is multiplied when you use them in tandem. The fanout capability of SNS extends to such services as Lambda functions and Kinesis Data Firehose delivery streams but also to SQS queries. In effect, SNS can “push” messages to SQS so that they will persist in SQS queues.

It works like this. You subscribe to one or more Amazon SQS queues to an Amazon SNS topic. When a message is published to the SNS topic, SNS then sends an SQS message to the subscribed queues. This is all done programmatically, and the resulting message can be viewed in JSON format.

Final Thoughts

We’ve learned that SNS pushes messages and SQS messages are pulled. Unlike SNS, SQS messages can persist for up to two weeks. SNS and SQS have different functions and operations, but they can work together quite nicely.

Didn’t get all that? Don’t feel bad. It takes more than a cursory glance to understand the intricacies of AWS messaging services. To learn more, take our AWS SQS vs SNS: How to Implement Amazon Simple Notification Service & Simple Queueing Service Online Training.

Not a CBT Nuggets subscriber? Create your account today.


Download

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522