avatarAshish Patel

Summary

AWS SQS is a queuing service that stores messages for distributed processing, while SNS is a publish-subscribe service for immediate message dissemination to multiple subscribers.

Abstract

AWS Simple Queue Service (SQS) is a managed queuing service that allows for decoupling of application components, enabling messages to be stored and processed asynchronously. It uses a pull mechanism where consumers fetch messages, which can be retained for up to 14 days. Amazon Simple Notification Service (SNS), on the other hand, is a fully managed publish-subscribe service that immediately pushes messages to subscribers, including support for various endpoints like email, SMS, and HTTP. SNS is ideal for scenarios requiring fan-out to multiple subscribers or systems for alerting and monitoring, with no message persistence if subscribers are unavailable. The choice between SQS and SNS depends on the use case, such as whether a single subscriber or multiple processing paths are needed, or if message persistence is a requirement. A combination of both services can be used to implement a fanout pattern for distributed processing.

Opinions

  • SQS is preferred for ensuring message delivery and handling scenarios where messages need to be processed sequentially without loss.
  • SNS is suitable for scenarios where messages need to be broadcast to multiple subscribers simultaneously, with each subscriber potentially processing the message in a unique way.
  • The fanout pattern, using both SNS and SQS, is recommended for scenarios requiring both immediate notification and distributed processing.
  • The author suggests that SNS is more ephemeral, with messages being delivered to available subscribers at the time of publishing, whereas SQS provides a buffer with message persistence.
  • The article implies that SQS consumers are expected to process messages identically, while SNS consumers are likely to process messages differently, catering to diverse application requirements.

AWS — Difference between SQS and SNS

Comparisons: SQS vs SNS in AWS — Simple Notification Service and Simple Queue Service.

Awesome Cloud — SNS and SQS

TL;DR:

SQS and SNS are important components for scalable, large-scale, distributed, cloud-based applications:

SNS is a distributed publish-subscribe service.

SQS is distributed queuing service.

Amazon SNS (Simple Notification Service)

Awesome Cloud — SNS

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.

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

SNS supports several end points such as email, sms, http end point and SQS. If you want unknown number and type of subscribers to receive messages, you need SNS.

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 users in the US or to email recipients worldwide.

Amazon SQS (Simple Queue Service)

Awesome Cloud — SQS

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

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).

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. Polling inherently introduces some latency in message delivery in SQS unlike SNS where messages are immediately pushed to subscribers.

Key Differences: SQS vs SNS

Entity Type SQS: Queue (similar to JMS, MSMQ). SNS: Topic-Subscriber (Pub/Sub system).

Message consumption SQS: Pull Mechanism — Consumers poll messages from SQS. SNS: Push Mechanism — SNS pushes messages to consumers.

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, gets the message and the message is deleted. If no consumers available then the message is lost.

In SQS message delivery is guaranteed but in SNS it is not.

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.

Use Cases

Choose SNS if:

  • You would like to be able to publish and consume batches of messages.
  • You would like to allow same message to be processed in multiple ways.
  • Multiple subscribers are needed. Fan-out messages to a large number of subscribers.
  • You need alerting and monitoring related to applications logs, infrastructure, etc.

Choose SQS if:

  • You need a simple queue with no particular additional requirements.
  • Decoupling distributed systems and allowing parallel asynchronous processing.
  • Only one subscriber is needed.
  • You need your messages are received sequentially and without any loss, even if some parts fail or the network experiences disruptions.

We can design fanout pattern by using both SNS and SQS. In this pattern, a message published to an SNS topic is distributed to multiple SQS queues in parallel.

Summary

SQS is mainly used to decouple applications. SNS distributes several copies of a message to several subscribers.

View more from Awesome Cloud

Happy Clouding!!!

Reference Link

AWS
Sqs
Sns
Queue
Pub Sub
Recommended from ReadMedium