Design Resilient Architectures · Topic 1 of 5

Loose Coupling with Queues and Events

Decouple application tiers with Amazon SQS, SNS, EventBridge, Kinesis and Amazon MQ, and learn when to choose a queue, a topic, an event bus or a stream.

  • 5 min
  • Includes a diagram
In a nutshell
  • Use a queue (SQS) to decouple and buffer, a topic (SNS) to fan out, and an event bus (EventBridge) to route by rules.
  • SQS standard gives at least once delivery with best effort order. FIFO gives order and deduplication.
  • A dead letter queue captures messages that keep failing.

What it is

Two components are tightly coupled when one calls the other directly and waits for the answer. If the receiver is slow or fails, the caller fails too, and both must scale together.

Loose coupling puts a buffer or a broker between them. The producer sends a message and moves on, and the consumer processes it when it can. Each side can then fail, scale and be updated on its own.

Web tierproducersends messageSQS queuebufferpollsWorker fleetconsumers

How it works

Amazon SQS: the queue

A web tier sends messages to an SQS queue and an Auto Scaling group of workers polls and deletes them, with failing messages moving to a dead letter queue and a CloudWatch alarm on the backlog adding workers. Amazon Simple Queue Service (SQS) stores messages until a consumer reads and deletes them. Consumers pull messages. The queue absorbs traffic spikes, and an Auto Scaling group can add workers when the backlog grows.

FeatureStandard queueFIFO queue
OrderingBest effortStrict order within a message group
DeliveryAt least once, so duplicates are possibleExactly once processing, with deduplication
ThroughputVery high, nearly unlimitedLower than standard
Pick it forMost workloads, where order does not matterOrder matters, such as bank transactions

Key settings follow.

  • Visibility timeout: after a consumer reads a message, it is hidden for a time. If the consumer does not delete it before the timeout ends, it becomes visible again and is retried.
  • Dead letter queue (DLQ): messages that fail too many times move to a separate queue for inspection.
  • Long polling: the consumer waits for messages instead of returning empty at once, which cuts empty responses and cost.
  • Retention: unread messages are kept for a period you configure, up to 14 days.

Amazon SNS: the topic

Amazon Simple Notification Service (SNS) is publish and subscribe. A publisher sends one message to a topic, and SNS pushes a copy to every subscriber: SQS queues, Lambda functions, HTTP endpoints, email, text messages and mobile push.

The classic design is fan out: one SNS topic feeds several SQS queues, so each downstream system processes the event independently and at its own pace. Subscription filter policies let each subscriber receive only the messages it needs.

Order servicepublishesSNS topicQueue AbillingOrder servicepublishesSNS topicQueue Bshipping

Amazon EventBridge: the event bus

Amazon EventBridge routes events by rules. It receives events from AWS services, your own applications and software as a service partners, and a rule matches patterns and sends matching events to targets such as Lambda, Step Functions or SQS. It can also run rules on a schedule and archive and replay events.

Choose EventBridge when you react to state changes in AWS (for example, an instance stopping) or need rich content based routing with many targets.

Amazon Kinesis Data Streams: the stream

Kinesis Data Streams is for ordered, high volume streams of records that several consumers may read, and that can be replayed within a retention period. Records with the same partition key go to the same shard and keep their order. Use it for clickstreams, logs and real time analytics rather than for simple work queues.

Amazon MQ

Amazon MQ is a managed broker for Apache ActiveMQ and RabbitMQ. Choose it when you migrate an existing application that depends on standard protocols such as Java Message Service (JMS), Advanced Message Queuing Protocol (AMQP) or MQTT (a lightweight messaging protocol) and you do not want to rewrite it for SQS or SNS.

Choosing quickly

RequirementService
Buffer work between tiers, one consumer groupSQS
Send one message to many subscribersSNS (often with SQS)
Route events by rules, from AWS or SaaS sourcesEventBridge
Ordered, replayable, high volume streamKinesis Data Streams
Existing app that needs JMS or AMQPAmazon MQ

Design habits that help

Make consumers idempotent, meaning that processing the same message twice gives the same result, because standard queues can deliver duplicates. Keep services stateless, and avoid a hard dependency on a fixed endpoint by using queues or load balancer names.

Exam tip

When the scenario says a front end overwhelms a back end, or orders are lost during spikes, add an SQS queue between them and scale the consumers on queue depth.

What to remember for the exam

  • Use a queue (SQS) to decouple and buffer, a topic (SNS) to fan out, and an event bus (EventBridge) to route by rules.
  • SQS standard gives at least once delivery with best effort order. FIFO gives order and deduplication.
  • A dead letter queue captures messages that keep failing.
  • A message stays invisible during the visibility timeout, and must be deleted after successful processing.
  • SNS plus SQS fan out lets many systems process one event independently.
  • Kinesis Data Streams keeps ordered records per shard for replay by multiple consumers.
  • Amazon MQ is the answer for lifting an application that uses JMS or AMQP.
  • Scale workers on the SQS queue depth, not only on CPU.

Common mistakes

Picking SNS when a buffer is needed. SNS pushes to subscribers and does not hold work for slow consumers. Use SQS for buffering, or SNS with SQS subscribers.

Expecting standard SQS to keep order. If order matters, use FIFO and a message group identifier.

Forgetting duplicates. Consumers must tolerate seeing a message more than once on a standard queue.

Using SQS for streaming replay. SQS deletes a message once processed. Reading the same data again, or by several independent readers, calls for Kinesis.

Watch out

A visibility timeout shorter than the processing time makes a second worker pick up the same message while the first is still working, which creates duplicate processing.

Check yourself

  • Which service lets one published message reach several SQS queues?

    Amazon SNS, using the fan out pattern with each queue subscribed to the topic.

  • What does a dead letter queue hold?

    Messages that could not be processed successfully after the allowed number of attempts.

  • When would you choose a FIFO queue over a standard queue?

    When message order and deduplication matter more than maximum throughput.

Topic 1 of 5 in Design Resilient Architectures

Test yourself on Design Resilient Architectures

The full AWS SAA-C03 question bank has 823 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.