Event-Driven Architecture with SQS, SNS and EventBridge
In an event-driven architecture services communicate by producing and consuming events instead of calling each other directly. Producers don’t wait for consumers, failures are isolated, and each part scales on its own.
flowchart LR
O[Order service] -->|OrderPlaced| SNS[(SNS topic orders)]
SNS --> Q1[[SQS: billing-queue]] --> L1[Lambda billing]
SNS --> Q2[[SQS: shipping-queue]] --> L2[Lambda shipping]
SNS --> EM[E-mail subscription]
EB{{EventBridge bus}} -->|"rule: detail-type = OrderCancelled"| L3[Lambda refunds]
S[Schedule: every day 02:00] --> EB
Amazon SQS – queues
| Concept | Meaning |
|---|---|
| Queue | Buffer of messages; consumers poll and delete after processing |
| Standard | Nearly unlimited throughput, at-least-once delivery, best-effort order |
| FIFO | Exactly-once processing, strict order per message group (300–3000 msg/s) |
| Visibility timeout | A received message is hidden while being processed; reappears if not deleted |
| Dead-letter queue (DLQ) | Messages that fail maxReceiveCount times are moved aside for inspection |
| Long polling | WaitTimeSeconds up to 20 s – fewer empty responses |
| Retention | 1 minute – 14 days (default 4 days) |
Lambda + SQS: an event source mapping polls the queue and invokes the function with batches; return partial batch failures so only failed messages are retried.
At-least-once delivery means a message can be processed twice. Make consumers idempotent (e.g. conditional writes on an order ID).
Amazon SNS – publish/subscribe
A topic pushes each published message to all subscriptions: SQS, Lambda, HTTP(S), e-mail, SMS, mobile push. Fan-out = SNS topic → several SQS queues, so each consumer gets its own durable copy. Message filtering policies deliver only matching messages to a subscriber.
Amazon EventBridge – event bus and router
| Concept | Meaning |
|---|---|
| Event bus | Default bus (AWS service events), custom buses, partner buses (SaaS) |
| Event | JSON with source, detail-type, detail |
| Rule | Event pattern that matches events → up to 5 targets (Lambda, SQS, Step Functions, API destinations…) |
| Scheduler | Cron/rate schedules (rate(5 minutes), cron(0 2 * * ? *)) |
| Archive & replay, schema registry, Pipes | Re-process events, discover schemas, point-to-point integrations |
{ "source": ["com.shop.orders"], "detail-type": ["OrderCancelled"], "detail": { "amount": [{ "numeric": [">", 1000] }] } }
Choosing
| Need | Use |
|---|---|
| Buffer work, smooth spikes, retries | SQS |
| Broadcast one message to many | SNS (often SNS → SQS fan-out) |
| Route events by content, integrate AWS/SaaS events, schedules | EventBridge |
| Coordinate multi-step workflows | Step Functions (next topic) |
Practise it
Virtual lab · Amazon Web Services · 45 min
Event-driven order processing with SQS, SNS, a dead-letter queue and EventBridge
Decouple an order system: an SNS topic fans out to an SQS queue, you receive and delete messages by hand, then a Lambda function consumes the queue, a poison message lands in the dead-letter queue, and an EventBridge rule routes OrderPlaced events to Lambda.
Quick revision
- Events decouple producers and consumers.
- SQS: poll, visibility timeout, DLQ, standard vs FIFO.
- SNS: push to many subscribers; fan-out to SQS.
- EventBridge: buses, rules with patterns, targets, schedules.
- Design consumers to be idempotent.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.