AWS offers two core messaging services, SQS and SNS, and picking the right one is crucial for building scalable and reliable distributed systems.

Imagine you’re building a system where one part needs to tell another part to do something, but they don’t necessarily need to talk directly. That’s where messaging services come in.

Here’s SQS, Simple Queue Service, in action. Let’s say an e-commerce order service needs to tell a shipping service to prepare a package.

{
  "order_id": "ORD12345",
  "customer_id": "CUST9876",
  "items": [
    {"sku": "SKU001", "quantity": 2},
    {"sku": "SKU005", "quantity": 1}
  ],
  "shipping_address": "123 Main St, Anytown, USA"
}

This JSON message is sent to an SQS queue named order-processing-queue. The shipping service, acting as a consumer, polls this queue. When it finds a message, it reads it, processes it (e.g., creates a shipping label), and then deletes the message from the queue. This ensures each message is processed exactly once.

SQS is like a mailbox: one sender, one receiver at a time. It’s perfect for decoupling tasks where you want to ensure a specific message is handled by a single worker. Think of it for background jobs, worker queues, or anywhere you need reliable, asynchronous task distribution.

Now, let’s look at SNS, Simple Notification Service. SNS is a publish/subscribe service. It’s designed for broadcasting messages to multiple subscribers.

Imagine a new product launch. The product service publishes a message to an SNS topic named product-launch-notifications.

{
  "event": "NEW_PRODUCT_LAUNCH",
  "product_name": "SuperWidget 3000",
  "launch_date": "2023-10-27"
}

This message is then delivered to all subscribers of the product-launch-notifications topic. These subscribers could be:

  • An SQS queue for marketing to process, sending out emails.
  • An AWS Lambda function to update website banners.
  • An HTTP endpoint for an external partner system.
  • An email address for a specific team.

SNS is like a radio station: one sender, many listeners, all at once. It’s ideal for fan-out scenarios where a single event needs to trigger multiple, independent actions.

The core difference boils down to the delivery model. SQS is a queue (point-to-point, one consumer processes one message), while SNS is a topic (publish/subscribe, one message to many subscribers). You can even combine them: SNS can publish messages to an SQS queue, enabling a fan-out pattern where each subscriber (each SQS queue) then processes its messages independently.

When you set up an SQS queue, you configure things like visibility timeout (how long a message is hidden from other consumers after being received) and dead-letter queues (where messages go if they can’t be processed). For SNS, you define topics and then create subscriptions to those topics, specifying the endpoint for each subscriber.

The most surprising thing about these services is how easily they can be misapplied. People often try to use SNS for task queues because it’s simpler to set up initially for a single subscriber, only to find they lose messages or have race conditions because SNS doesn’t guarantee message persistence or exactly-once processing for individual consumers in the same way SQS does. SNS guarantees at-least-once delivery to its subscribers, and if a subscriber fails to acknowledge, SNS will retry. But if you need to ensure a message is processed by one specific worker and then removed, SQS is the tool.

Understanding the underlying mechanics of message acknowledgment and visibility timeout in SQS, and the fan-out versus point-to-point delivery of SNS, is key. For instance, in SQS, if a consumer receives a message and crashes before deleting it, the message will reappear in the queue after its visibility timeout expires, allowing another consumer to pick it up. This is how SQS ensures durability and enables retries.

The next step in mastering AWS messaging is understanding how to integrate these services with other AWS components like Lambda and EventBridge for even more sophisticated event-driven architectures.

Want structured learning?

Take the full Aws course →