Skip to content
BytePatterns

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.

  1. Shipping's copy waits in its queue while shipping is down
  2. SNS pushes a copy into each subscribed queue
  3. After repeated failures a bad message moves to the DLQ
  4. The order service publishes one event to the topic

Mini quiz

1 / 3

Standard SQS queues deliver messages:

Sources

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.