Today I learned about the difference between Amazon SQS – Simple Queue Service, and Amazon SNS – Simple Notification Service.
Both help you send messages between decoupled Lambda Functions 🤨
So why two different things?
SQS is a true queueing service. You place messages on a queue and they are processed roughly in sequence. FIFO queues exist but that's extra.
Easiest way to use is to have Lambdas triggered from SQS events.
Once your lambda succeeds, that message is deleted and won't be processed again.
SQS keeps retrying until you successfully process a message. You can configure a max number of retries. Once reached, the message is moved to a dead letter queue where it waits for you to debug.
SNS on the other hand is ... a queuing service. But instead of a true queue, it's a pubsub system. Messages are published and subscribers receive them.
Each message is published once and if nobody receives it, the message is gone.
Wait so if SNS is super lossy and SQS is super reliably ... why would you ever use SNS?
SNS is convenient because the same message can be processed by multiple subscribers.
Use SQS when you want reliability.
Use SNS when you want one signal to trigger multiple things.