DEV Community

Cover image for SNS, SQS or both?

SNS, SQS or both?

helenanders26 profile image Helen Anderson Originally published at Updated on ・3 min read

By combining pub/sub and queueing components we are able to build resilient, scalable and fault-tolerant architecture with AWS. This is an overview of SNS (Simple Notification Service), SQS (Simple Queue Service) and how they can be used in isolation or together to send persistent and immediate messages.

What is SNS?
When to use SNS
What is SQS?
When to use SQS
When to use them together

What is SNS?

  • SNS is a fully managed pub/sub messaging service from AWS.

  • It is used in application integration and allows apps and services to communicate with messages when these are decoupled.

  • Messages are in JSON format and are pushed to subscribers.

  • 'Topics' are logical access points and allow recipients to subscribe to identical copies of the same message.

  • Notifications are then formatted for the protocol receiving the message and can be delivered as text messages, emails, and to SQS or HTTP endpoints.


When to use SNS

  • SNS can be used to send large numbers of time-sensitive messages to end-users in the form of a push notification, SMS and email. Clients can subscribe to topics and specify the endpoint.

  • In this example from Adnan we see how SNS can be used in conjunction with Lambda to perform calculations. By using SNS we ensure that the message gets through.

What is SQS?

  • SQS is a fully managed message queue service from AWS.

  • It is used in application integration and allows apps and services to communicate with messages when these are decoupled.

  • SQS can store messages up to 256KB in any format for up to 12 hours while waiting for a system to pull them to process them.

  • If the job isn’t processed before the time out expires the message will be placed back in the queue, which could cause the message to be processed twice.

  • Auto-scaling groups can monitor the SQS group and scale up and down depending on the number of messages in the queue.

  • The Standard queue uses 'best-effort' ordering, FIFO queues guarantee messages are pulled in the order that they arrive.

  • By default short polling returns messages immediately. Long polling waits until there is a message in the queue or until the timeout expires.


When to use SQS

  • SQS can be used to throttle workload and process work in batches with non-time sensitive messages being stored for up to 14 days.

  • In this example from Marcin we see how using dead letter queues allows error handling logic from the application logic

When to use them together

  • By combining SNS topics and SQS queues together, you can send immediately and persisted messages.

  • In this example from Frank in his excellent AWS series, we see how to use SNS, SQS and Lambda together.

  • The architecture involves S3 event notifications, an SNS topic, an SQS queue, and a Lambda function sending a message to the Slack channel. This shows how it is possible to implement an event processing pipeline with potentially multiple consumers and producers.

Useful Links:

Read more:

Discussion (2)

Editor guide
andrewbrown profile image
kp profile image

@helenanders26 have you managed to get Amazon SES working with SNS notifications? Would love to ask a question on this if you're open to it.