Architecture Design and Implementation Built for the Cloud · Topic 1 of 11

Event-Driven Messaging and Event Routing

Pick SQS, SNS, EventBridge or Kinesis by ordering, delivery and idempotency needs, route events across accounts and Regions, and design WebSocket push.

  • 5 min
In a nutshell
  • SQS FIFO orders within a message group ID and deduplicates within a deduplication interval. Standard queues can deliver duplicates and out of order.
  • Kinesis orders per shard by partition key and lets several consumers replay the stream.
  • EventBridge routes on event content to many targets. SNS fans out the same message to all subscribers.

What it is

An event-driven architecture lets producers emit messages or events without knowing who consumes them. Consumers react on their own schedule, so a slow or failed consumer does not break the producer.

At the professional level the question is never "should we decouple". It is which messaging service gives the ordering, delivery guarantee and fan-out the scenario needs, and how events travel between accounts, Regions and connected clients.

Produceremits eventpublishRouterEventBridge or SNSdeliverQueue or streamSQS or KinesispollConsumeridempotent handler

How it works

Choosing the messaging service

ServiceModelOrderingDeliveryPick it when
SQS standardQueue, one consumer groupBest effortAt least once, duplicates possibleBuffering work at very high throughput
SQS FIFOQueueStrict within a message group IDExactly once processing with deduplicationOrder matters per entity, such as per account or per order
SNS standardPush fan-outNoneAt least onceOne message to many subscribers
SNS FIFOPush fan-out to SQS queuesPer message groupDeduplicatedOrdered fan-out
EventBridgeEvent bus with content rulesNoneAt least once, with retries and DLQRouting by event content, SaaS and AWS service events, many targets
Kinesis Data StreamsOrdered log with replayPer shard, chosen by partition keyAt least onceOrdered streams, several readers, replay of history

FIFO ordering is scoped to the message group ID. Use many group IDs (one per customer, for example) so different groups process in parallel while each group stays ordered.

Kinesis orders records per shard, and the partition key decides the shard. A hot partition key overloads one shard, so pick a key with high cardinality.

Idempotency and failure handling

Most services deliver at least once, so every consumer must be idempotent. A common pattern stores a processed message ID or business key in DynamoDB with a conditional write, and skips the work if the key already exists.

  • Dead-letter queues catch messages that fail after a set number of receives, so one poison message does not block the queue.
  • Visibility timeout must be longer than the processing time, or the message reappears and runs twice.
  • Partial batch responses let a Lambda function report only the failed items in an SQS or Kinesis batch, so the whole batch is not retried.

Cross-account and cross-Region routing

EventBridge rules can target an event bus in another account or Region. The receiving bus needs a resource-based policy that allows the sender (an account ID or the whole organization), and the sending rule uses an IAM role.

Workload accountdefault busrule forwardsCentral bussecurity accountrulesTargetsSIEM, Lambda, SQSCentral busprimary Regionrule forwardsEvent busrecovery Region

Events do not chain. If a receiving account forwards events it received from another account on to a third account, EventBridge does not deliver them. Design a hub that receives directly from every source.

For Regional resilience, EventBridge global endpoints pair a primary and secondary Region, use a Route 53 health check to fail over publishing, and can replicate events to the secondary Region.

WebSocket and publish-subscribe for real time

API Gateway WebSocket APIs keep a two-way connection open to each client. The $connect, $disconnect and $default routes invoke a backend, usually Lambda.

The backend stores each connection ID, often in DynamoDB. To push a message, it posts to the connection through the API's callback URL, so the server can send without the client polling.

ClientbrowserWebSocketAPI GatewayWebSocket APIconnect routeLambdastore connection IDsavesDynamoDBconnection tableEventprice updatetriggersLambdafan outposts toAPI Gatewaycallback URLpushesClient

Pair the WebSocket API with SNS or EventBridge when many backend producers must reach many connected clients. Producers publish once, and a fan-out function pushes to each stored connection.

How the exam asks about this

  • "Payment events for each account must be processed in order, but different accounts should process in parallel" -> SQS FIFO with the account ID as the message group ID.
  • "Fifty workload accounts must send security findings to one central account with minimal custom code" -> EventBridge rules in each account that target a central event bus allowed by an organization-wide resource policy.
  • "A trading dashboard must push price changes to thousands of browsers without polling" -> API Gateway WebSocket API with connection IDs stored in DynamoDB and a backend that posts through the callback URL.

What to remember for the exam

  • SQS FIFO orders within a message group ID and deduplicates within a deduplication interval. Standard queues can deliver duplicates and out of order.
  • Kinesis orders per shard by partition key and lets several consumers replay the stream.
  • EventBridge routes on event content to many targets. SNS fans out the same message to all subscribers.
  • Consumers must be idempotent, because at least once delivery is the norm.
  • Cross-account EventBridge needs a resource policy on the receiving bus. Events received from another account are not forwarded again.
  • WebSocket APIs keep connections open for server push; store connection IDs outside the function.
Watch out

Exactly once processing in SQS FIFO is not end-to-end exactly once. If the consumer writes to a database and then crashes before deleting the message, the message is processed again, so the write must still be idempotent.

Common mistakes

Using one message group ID for everything. A single group serializes the whole FIFO queue to one consumer at a time. Choose a group ID that matches the real ordering boundary.

Expecting multi-hop event forwarding. Designs that pass events from account A to B to C fail silently, because EventBridge does not forward events that arrived from another account. Route every source to the hub directly.

Polling for real-time updates. Short polling a REST API from thousands of clients wastes requests and adds latency. A WebSocket API pushes changes the moment they happen.

Check yourself

  • How do you keep per-customer ordering but still process many customers in parallel?

    Use an SQS FIFO queue with the customer ID as the message group ID, so each group is ordered and groups run in parallel.

  • What must the receiving account configure to accept EventBridge events from other accounts?

    A resource-based policy on its event bus that allows the sending accounts or the organization to put events.

  • How does a backend send a message to one WebSocket client?

    It looks up the stored connection ID and posts the message to that connection through the API Gateway callback URL.

Topic 1 of 11 in Architecture Design and Implementation Built for the Cloud

Test yourself on Architecture Design and Implementation Built for the Cloud

The full AWS SAP-C03 question bank has 850 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.