How to choose between SQS and SNS?

Mohit Kaushal
3 min readJun 29, 2022
(Image Credit: Amazon)

Amazon Web Services provide us services of SNS and SQS which bring message transfer at its ease.

What is SNS?

SNS Model

SNS stands for (Simple Notification Service), this service is based on the publisher and subscriber model which deliver a message to multiple subscribers as soon as it is received from the publisher. We have two types of SNS i.e, Standard and FIFO. Subscribers in SNS can be:

  • Email
  • SMS
  • SQS
  • HTTP Endpoints

What is SQS?

SQS Model

SQS stands for (Simple Queue Service), It is a fully distributed and managed queueing service. Subscribers have to pull messages from an SQS and then delete it. SQS can retain any message to a max of 14 days and the default is about 4 days. SQS can deliver messages to a single subscriber at a time. We have two types of SNS i.e, Standard and FIFO.

Primary Difference between SNS and SQS:

  • SQS uses a pull mechanism whereas SNS uses a push mechanism. SQS does not push messages to the subscribers, subscribers have to poll the queue, and as soon as one of them receives a message, the message is out of the queue and no other subscriber can access it. This polling inevitably introduces a certain latent delay in message delivery.
  • SNS pushes the message to multiple subscribers, so there is no latency in this.
  • Data remains stored in SQS until the subscriber pulls that data but in SNS message is pushed and if the subscriber is down then the data get lost.

Selection of SQS or SNS:

  • Selection totally depends upon your use case.
  • If data loss is not a major concern and multiple subscribers are needed then you have to use SNS but in cases where data is more important than subscribers then you should go with SQS.
  • In some cases where you need both multiple subscribers and data protection then you can use SNS and SQS both by using SQS as one of the subscribers of SNS.

--

--

Mohit Kaushal

Hi, I’m Mohit Kaushal currently working as a software engineer and willing to make some changes by sharing knowledge with persons having the same interests.