Different between Amazon SQS and SNS
devops

Different between Amazon SQS and SNS

Sage Huynh

Amazon SQS and Amazon SNS are two popular tools for engineers when designing distributed systems in the AWS cloud ecosystem.

It can be useful if we understand what are the similarities and differences between these tools. I'm going to introduce that to you down below.

Amazon SQS:

a0794b0e-88aa-4712-801e-e2bd9122fa6d

  1. Used for Application to Application messaging
  2. Communication Channel: Queue
  3. Pull/Poll mechanism
  4. Typical queueing, producer/consumer paradigm
  5. 14 days message retention
  6. Two variants, Standard and FIFO
  7. Guarantees exactly delivery
  8. Maximum Message Size: 256 KB
  9. Provides no message filtering
  10. Supports Cross-Region messaging
  11. Does not support Message Schema Registry

Amazon SNS:

5b20b24b-7271-4127-837c-8cdda1ed7a99

  1. Used for Application to Application messaging as well as application to Person notification
  2. Communication Channel: Queue
  3. Push mechanism with retry
  4. Publisher/Subscriber messaging
  5. 14 days message retention
  6. Two variants, Standard and FIFO
  7. Guarantees at least once delivery
  8. Maximum Message Size: 256 KB
  9. Provides some message filtering
  10. Supports Cross-Region messaging
  11. Does not support Message Schema Registry

Differences:

Entity Type

  • SQS : Queue
  • 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. Which ever consumer is present at the time of message arrival, get the message and the message is deleted. If no consumers available then the message is lost.
  • In SQS the 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 processing the messages in different ways.

When to use?

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.

Choose SQS if:

  • You need a simple queue with no particular additional requirements.
  • Decoupling two applications and allowing parallel asynchronous processing.
  • Only one subscriber is needed.

That's it! Thanks for reading!