SNS vs SQS

Here’s a comparison of the two:

Entity Type

  • SQS : Queue (Similar to JMS)
  • SNS : Topic (Pub/Sub system)

Message consumption

  • SQS : Pull Mechanism – Consumers poll and pull messages from SQS
  • SNS : Push Mechanism – SNS Pushes messages to consumers

Use Case

  • SQS : Decoupling 2 applications and allowing parallel asynchronous processing
  • SNS : Fanout – Processing the same message in multiple ways

Persistence

  • SQS : Messages are persisted for some (configurable) duration if no consumer is available
  • SNS : No persistence. Whichever consumer is present at the time of message arrival gets the message and the message is deleted. If no consumers are available then the message is lost.

Consumer Type

  • SQS : All the consumers are supposed to be identical and hence process the messages in exact same way
  • SNS : The consumers might process the messages in different ways

Sample applications

  • SQS : Jobs framework: The Jobs are submitted to SQS and the consumers at the other end can process the jobs asynchronously. If the job frequency increases, the number of consumers can simply be increased to achieve better throughput.
  • SNS : Image processing. If someone uploads an image to S3 then watermark that image, create a thumbnail and also send a Thank You email. In that case S3 can publish notifications to a SNS Topic with 3 consumers listening to it. 1st one watermarks the image, 2nd one creates a thumbnail and the 3rd one sends a Thank You email. All of them receive the same message (image URL) and do their processing in parallel.

https://aws.amazon.com/blogs/aws/queues-and-notifications-now-best-friends/

https://stackoverflow.com/questions/13681213/what-is-the-difference-between-amazon-sns-and-amazon-sqs

Leave a comment