⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All AWS & Cloud Architecture Interview Questions Scenario 58 of 179 in AWS & Cloud Architecture
Junior / Associate DevOps [L1] AWS Cost & Architecture Core Fundamentals [L1]
🎯 Target Role / Context: AWS Scenario #56 (L1) · Cost & Architecture

Q: What is the difference between SQS and SNS?

The difference between SQS and SNS is delivery model: SQS is a pull-based message queue where one consumer group processes each message, while SNS is a push-based publish/subscribe topic that copies each message to every.

#AWS #Cost & Architecture #L1 #Cloud #Infrastructure
🎙️ Candidate Opening & Architectural Context
"The <strong>difference between SQS and SNS</strong> is delivery model: SQS is a pull-based message queue where one consumer group processes each message, while SNS is a push-based publish/subscribe topic that copies each message to every subscriber. Interviewers ask this because the two are constantly combined, and candidates who can only recite definitions miss the real design question: how do you decouple producers from consumers, absorb bursts, and fan out one event to several independent workflows without losing messages? A strong answer gives the mental model, shows the SNS-to-SQS fan-out pattern, and names the failure modes such as poison messages and missing queue policies."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? Stephane Maarek's AWS Certified DevOps Engineer Professional Masterclass on Udemy covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: The <strong>difference between SQS and SNS</strong> is delivery model: SQS is a pull-based message queue where one consumer group processes each message, while SNS is a push-based publish/subscribe topic that copies each message to every subscriber. Interviewers ask this because the two are constantly combined, and candidates who can only recite definitions miss the real design question: how do you decouple producers from consumers, absorb bursts, and fan out one event to several independent workflows without losing messages? A strong answer gives the mental model, shows the SNS-to-SQS fan-out pattern, and names the failure modes such as poison messages and missing queue policies.

1️⃣

Mental model: queue (SQS) vs topic (SNS)

SQS stores messages until a consumer asks for them; SNS does not store anything for you, it pushes to whoever is subscribed at publish time.

  • SQS: a durable buffer. Consumers poll (ReceiveMessage), process, then delete. Unprocessed messages wait until retention expires (4 days by default, configurable up to 14). Each message is handled by one consumer, so adding consumers scales throughput, not the number of recipients.
  • SNS: a topic with many subscribers. A publish is delivered to every subscription (SQS, Lambda, HTTPS, email, SMS, mobile push, Firehose). SNS retries according to the protocol's delivery policy but is not a long-term store.
  • Coupling: with SQS the consumer controls the pace and can fall behind safely. With SNS the subscriber must keep up or lose the delivery after retries, which is why durable subscribers are usually SQS queues.
  • Ordering and duplicates: standard queues and topics are at-least-once with best-effort ordering. FIFO variants add strict ordering per message group and deduplication.
  • Rule of thumb: if you can name the consumers in advance and each needs its own copy, think SNS; if you only care that the work eventually gets done by someone, think SQS.
Pro Tip: Short answer for the room: SQS decouples in time (buffering), SNS decouples in recipients (fan-out). Together they do both.
2️⃣

Hands-on: SNS-to-SQS fan-out with the AWS CLI

Create one topic and two queues, allow the topic to write to each queue, then subscribe them.

TOPIC_ARN=$(aws sns create-topic --name orders --query TopicArn --output text)
Q_URL=$(aws sqs create-queue --queue-name orders-billing --query QueueUrl --output text)
Q_ARN=$(aws sqs get-queue-attributes --queue-url "$Q_URL" \
  --attribute-names QueueArn --query Attributes.QueueArn --output text)

# Allow only this topic to send to the queue
cat > policy.json <<EOF
{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
 "Principal":{"Service":"sns.amazonaws.com"},"Action":"sqs:SendMessage",
 "Resource":"$Q_ARN",
 "Condition":{"ArnEquals":{"aws:SourceArn":"$TOPIC_ARN"}}}]}
EOF
aws sqs set-queue-attributes --queue-url "$Q_URL" \
  --attributes "$(jq -n --slurpfile p policy.json '{Policy: ($p[0]|tojson)}')"

aws sns subscribe --topic-arn "$TOPIC_ARN" --protocol sqs --notification-endpoint "$Q_ARN" \
  --attributes '{"RawMessageDelivery":"true","FilterPolicy":"{\"event\":[\"order_placed\"]}"}'

aws sns publish --topic-arn "$TOPIC_ARN" --message '{"id":42}' \
  --message-attributes '{"event":{"DataType":"String","StringValue":"order_placed"}}'
  • Queue policy is mandatory: an SQS queue only accepts messages from SNS if its access policy allows sqs:SendMessage from the topic ARN. A missing policy is the top cause of 'subscription confirmed but nothing arrives'.
  • Raw message delivery: set RawMessageDelivery=true on the subscription if consumers should receive the original body rather than the SNS JSON envelope.
  • Filter policies: attach a FilterPolicy to each subscription so billing only receives order_placed events, for example, instead of filtering in code.
  • Cross-account: add the publisher or subscriber account to the topic and queue policies explicitly.
Advertisement
3️⃣

Verify delivery and consumption

Confirm the message landed, was received once by a consumer, and was deleted.

# Long-poll, process, then delete
aws sqs receive-message --queue-url "$Q_URL" --wait-time-seconds 10 \
  --attribute-names ApproximateReceiveCount --max-number-of-messages 1
aws sqs delete-message --queue-url "$Q_URL" --receipt-handle "<receipt-handle>"

# Attach a DLQ so poison messages stop cycling (DLQ_ARN from get-queue-attributes)
aws sqs set-queue-attributes --queue-url "$Q_URL" \
  --attributes '{"RedrivePolicy":"{\"deadLetterTargetArn\":\"'"$DLQ_ARN"'\",\"maxReceiveCount\":\"5\"}","VisibilityTimeout":"60"}'
  • Peek at the queue: aws sqs receive-message --queue-url "$Q_URL" --wait-time-seconds 10 uses long polling, which reduces empty responses and cost compared with short polling.
  • Delete after success: aws sqs delete-message --queue-url "$Q_URL" --receipt-handle <handle>. If you never delete, the message reappears once the visibility timeout expires.
  • Queue depth: watch ApproximateNumberOfMessagesVisible and ApproximateAgeOfOldestMessage in CloudWatch; the age metric is the best backlog alarm.
  • SNS side: check NumberOfNotificationsFailed and enable delivery status logging for non-SQS endpoints.
4️⃣

Failure modes and when to use which

Choose by the question 'who needs this message and what happens if they are down?'.

  • Use SQS alone: one worker fleet processes jobs (image resize, email send) and you need buffering, retries and a dead-letter queue (DLQ) with maxReceiveCount.
  • Use SNS alone: notify humans or HTTP endpoints (email, SMS, push) where a missed delivery is acceptable or handled elsewhere.
  • Use SNS to SQS: several independent services must each process every event at their own pace. Each gets its own queue and DLQ, so one slow or broken consumer never blocks the others.
  • FIFO: SNS FIFO topics can fan out to SQS FIFO queues when order and deduplication matter. Throughput is lower than standard, so check current quotas.
  • Poison messages: without a DLQ a bad message cycles forever. Set a redrive policy and alarm on DLQ depth.
  • Cost and scale: both are fully managed and scale without capacity planning, so choice rests on semantics, not throughput; check current quotas for FIFO.
5️⃣

Production practice

Codify the wiring and make backlog visible.

  • IaC: define topic, queue, policy and subscription together in Terraform or CloudFormation so the queue policy cannot be forgotten.
  • Encryption: if the topic or queue uses a customer managed KMS key, grant sns.amazonaws.com permission to use it, otherwise publishes fail silently from the producer's view.
  • Idempotency: design consumers to tolerate duplicates; at-least-once delivery makes this unavoidable on standard queues.
  • Alarms: alert on oldest-message age and DLQ depth, not just queue length.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Always fan out with one SQS queue per consuming service behind a single SNS topic, and put a DLQ plus a queue policy scoped to the topic ARN on every queue."
⚡ 60-Second Elevator Pitch Talking Points
  • SQS is a pull-based queue that buffers work for one consumer group; SNS is a push-based topic that copies each message to every subscriber.
  • I verify by checking the queue policy, long-polling a receive, and watching message age and DLQ depth in CloudWatch.
  • I automate topic, queues, policies and filter policies in IaC and design consumers to be idempotent because delivery is at-least-once.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Subscribing a queue to a topic without a queue access policy SNS gets denied when sending, so the subscription looks healthy but the queue stays empty.
  2. Using SNS directly to a Lambda or HTTP endpoint for work that must not be lost SNS is not a durable backlog; a queue in between gives buffering, retries and a DLQ.
  3. Forgetting to delete messages or setting the visibility timeout shorter than processing time Messages reappear and are processed again, producing duplicates and runaway retries.
  4. Expecting strict ordering from standard queues and topics Only FIFO provides ordering per message group; standard is best-effort.
Advertisement
Want more AWS & Cloud Architecture scenarios?
Explore our complete collection of scenario-based AWS & Cloud Architecture interview runbooks.
Browse All AWS & Cloud Architecture Questions →