SQS vs SNS vs EventBridge
AWS for Interviews: lesson 7 of 18
Pull from a queue, push to many, or route by what the event says.
Lesson 7 of 18 · 7 min
SQS vs SNS vs EventBridge
Step 1 of 10
An order is placed. Billing and shipping both care — and the order service should not need to know either of them exists.
The Idea
SQS is a queue that consumers pull from: a received message is hidden for the visibility timeout and deleted when done. Standard queues deliver at least once, so consumers must be idempotent. SNS is pub/sub: a topic pushes a copy to every subscriber. EventBridge is an event bus whose rules match an event's content and route it to targets.
Real-World Example
An order service publishes one event to an SNS topic; billing and shipping each own an SQS queue subscribed to it. If shipping is down, its copy waits. A message that keeps failing moves to a dead-letter queue after maxReceiveCount receives.
The Tradeoff
Fan-out decouples teams but gives each queue its own copy to process and monitor. FIFO queues add ordering within a message group and exactly-once processing. EventBridge routes by content to many targets without glue code.
Hands-On
# illustrative — ARNs are placeholders; the queue's access policy must
# allow the topic to send to it
aws sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:orders \
--protocol sqs --notification-endpoint arn:aws:sqs:us-east-1:123456789012:billing
aws sqs set-queue-attributes \
--queue-url https://sqs.us-east-1.amazonaws.com/123456789012/billing \
--attributes file://redrive.json
# redrive.json: {"RedrivePolicy": "{\"deadLetterTargetArn\":
# \"arn:aws:sqs:us-east-1:123456789012:billing-dlq\",\"maxReceiveCount\":\"5\"}"}
Your turn
Put the steps in the right order.
- Shipping's copy waits in its queue while shipping is down
- SNS pushes a copy into each subscribed queue
- After repeated failures a bad message moves to the DLQ
- The order service publishes one event to the topic
Mini quiz
1 / 3
Standard SQS queues deliver messages:
Sources
- Amazon SQS visibility timeout — Amazon SQS Developer Guide
- Using dead-letter queues in Amazon SQS — Amazon SQS Developer Guide
- What is Amazon SNS? — Amazon SNS Developer Guide
- Rules in Amazon EventBridge — Amazon EventBridge User Guide