AWS SQS vs SNS: queues vs pub/sub
Two AWS messaging services that sound alike and solve different problems. SQS is a queue: messages wait until one worker processes them. SNS is a topic: every message is pushed to all subscribers at once. And the fan-out pattern that combines both.
In one sentence
SQS stores messages until one consumer pulls and processes each of them; SNS pushes each message to every subscriber immediately and doesn't store it.
See the difference
Switch between the three patterns. In SQS, make a worker fail and watch messages get retried and finally land in the dead-letter queue. In fan-out, notice how the slow analytics worker only backs up its own queue.
SQS: a queue (point-to-point)
- Producers send messages; they stay in the queue (up to 14 days) until a consumer receives them.
- Consumers poll (ideally with long polling) and process at their own pace.
- While a message is being processed it's hidden (visibility timeout). If the consumer doesn't delete it in time, it becomes visible again and is retried.
- After N failed attempts it moves to a dead-letter queue (DLQ) for inspection.
- Standard queues: nearly unlimited throughput, at-least-once delivery, best-effort order. FIFO queues: strict order and exactly-once processing, with lower throughput.
Use it to decouple a fast producer from slower work: order processing, sending emails, resizing images, writing to a database at a safe pace.
SNS: a topic (publish / subscribe)
- A publisher sends one message to a topic.
- SNS pushes a copy to every subscriber: SQS queues, Lambda functions, HTTP endpoints, email, SMS, mobile push.
- It doesn't keep messages for later: if an HTTP subscriber is down, SNS retries for a while and then gives up (or sends to a DLQ if you configured one).
- Filter policies let each subscriber receive only the messages it cares about (for example
type = "refund").
Use it when one event must trigger many independent reactions: "order placed" → charge the card, email the customer, update analytics, notify the warehouse.
Side by side
| SQS | SNS | |
|---|---|---|
| Model | Queue (point-to-point) | Topic (pub/sub) |
| Delivery | Consumers pull | SNS pushes |
| Who gets a message | One consumer | Every subscriber |
| Storage | Keeps messages until processed | No storage, deliver now |
| Retries | Visibility timeout + DLQ | Delivery retries per protocol |
| Typical use | Background jobs, buffering, smoothing load | Notifications, broadcasting events |
Fan-out: SNS + SQS together
The most common production pattern: publish an event to an SNS topic and subscribe one SQS queue per service. Each service gets its own durable copy, processes it at its own pace, retries on its own, and a slow or broken consumer doesn't affect the others.
Key takeaways
- 01SQS = queue: messages wait, one consumer processes each, failures are retried and end in a DLQ.
- 02SNS = topic: each message is pushed to all subscribers at once, nothing is stored.
- 03Fan-out (SNS → several SQS queues) gives each service its own durable copy of every event.
- 04Consumers must be idempotent: with at-least-once delivery the same message can arrive twice.
Check your understanding
1 of 3
What's the key difference between SQS and SNS?
Related concepts
Async writes with a queue
Instead of writing to the database during the request, the API puts the write in a queue and answers immediately; workers drain the queue at a pace the database can handle.
7 min read →AWS Lambda
AWS Lambda runs a function only when an event arrives, scales to many copies by itself and bills per millisecond, but each run is capped at 10 GB of memory and 15 minutes.
8 min read →Polling
Polling means the client keeps asking the server "anything new?" on a timer. It's the simplest way to get updates, and also the most wasteful.
6 min read →Kafka vs queues
A queue (SQS, RabbitMQ) deletes each message once one consumer handles it. A log (Kafka, Kinesis) keeps events in order for days; every consumer group tracks its own offset, so many services read the same stream and can replay it.
7 min read →