Event-driven Architecture
Overview
In an event-driven architecture (EDA), services communicate by emitting and reacting to events, which are facts that something happened: "an object was uploaded", "an order was placed", "an instance stopped". The producer does not know or care who reacts. Consumers subscribe to the events they care about and act independently.
This style makes systems loosely coupled, easy to extend and naturally scalable. AWS provides the plumbing: Amazon EventBridge (serverless event bus with routing rules), SNS and SQS (messaging), Lambda (compute that reacts to events), Kinesis (ordered streams) and Step Functions (workflow orchestration).
The exam rarely asks for deep implementation. Instead it gives a scenario and asks you to choose the right service for routing, buffering, streaming or orchestrating, so knowing how these services differ is the main goal of this lesson.
Key Concepts
- EventBridge is a serverless event bus: events from AWS services, your apps and SaaS partners are matched by rules and routed to targets.
- The default event bus receives AWS service events; custom buses carry your own app events; partner buses receive SaaS events.
- Event patterns filter on event content (prefix, numeric, exists, anything-but); rules can also run on a schedule (cron/rate).
- Archive and replay store events and re-send them later; the Schema Registry discovers event structures.
- EventBridge Pipes connect a source (SQS, Kinesis, DynamoDB streams) to a target with optional filtering and enrichment; EventBridge Scheduler runs one-off or recurring tasks at scale.
- Step Functions orchestrates multi-step workflows with retries, branching, parallelism and human approval; Standard (up to 1 year) vs Express (up to 5 minutes).
- Kinesis Data Streams provides ordered, replayable streams (retention 24 h default, up to 365 days) for high-volume event data.
- Choreography (services react to events) vs orchestration (a central coordinator such as Step Functions directs the flow).
Detailed Notes
Events, buses, rules and targets
An event is a JSON document describing a state change. EventBridge receives events on an event bus. A rule has an event pattern (or a schedule) and one or more targets (Lambda, SQS, SNS, Step Functions, Kinesis, ECS tasks, API destinations, another bus in a different account or Region, and many more).
{
"source": ["aws.s3"],
"detail-type": ["Object Created"],
"detail": {
"bucket": { "name": ["invoices-prod"] },
"object": { "key": [{ "suffix": ".pdf" }] }
}
}
EventBridge was formerly CloudWatch Events and uses the same underlying API. Most AWS services emit events there automatically, such as EC2 state changes, GuardDuty findings, CodePipeline state and Auto Scaling.
Choosing the right integration service
| Service | Pattern | Delivery | Best for |
|---|---|---|---|
| SQS | Queue (pull) | Stored up to 14 days | Buffering work, load levelling |
| SNS | Pub/sub (push) | Not stored | Fan-out, notifications |
| EventBridge | Event bus + rules | Push, archive/replay | Routing by content, SaaS and AWS events, decoupled microservices |
| Kinesis Data Streams | Ordered stream | Pull, retained 24 h-365 d | Real-time analytics, multiple replaying readers |
| Step Functions | Workflow | State machine | Multi-step processes with error handling |
| Amazon MQ | Managed ActiveMQ/RabbitMQ | Protocol based | Migrating apps that use JMS, AMQP, MQTT |
Choreography vs. orchestration
- Choreography: each service emits events and reacts to others. Highly decoupled, but the overall flow is harder to see.
- Orchestration: Step Functions holds the workflow definition (Amazon States Language), calls Lambda, ECS, DynamoDB, SNS and 200+ services directly, and provides retry, catch, parallel, map, wait states plus a visual execution history. Use it for the saga pattern (compensating actions when a step fails).
| Step Functions type | Max duration | Semantics | Typical use |
|---|---|---|---|
| Standard | 1 year | Exactly-once | Long-running, auditable workflows, human approval |
| Express | 5 minutes | At-least-once (async) | High-volume streaming, IoT, microservice glue |
Lambda in event-driven designs
Lambda can be invoked synchronously (API Gateway, ALB), asynchronously (S3, SNS, EventBridge; automatic retries up to 2 with on-failure destinations or DLQ) or via event source mapping that polls SQS, Kinesis and DynamoDB Streams. Understanding which mode applies determines retry and error-handling behaviour.
Reliability patterns
- Put an SQS queue between EventBridge and a slow consumer to buffer and retry.
- Set a DLQ on rule targets so events that cannot be delivered are saved.
- Make handlers idempotent; at-least-once delivery means duplicates happen.
- Use archive and replay to rebuild state or recover after a bug.
Cross-account and multi-Region events
A rule can target an event bus in another account or Region, enabling centralised security or audit buses. The target bus needs a resource policy permitting the source. Global endpoints add automatic failover of custom event ingestion between Regions.
aws events put-rule --name s3-invoice-created --event-pattern file://pattern.json
aws events put-targets --rule s3-invoice-created \
--targets "Id"="1","Arn"="arn:aws:states:us-east-1:111122223333:stateMachine:ProcessInvoice"
Real World Example
Scenario — a logistics company automates invoice processing.
Suppliers upload PDF invoices to an S3 bucket. S3 sends Object Created events to EventBridge. A rule filters for the .pdf suffix and starts a Step Functions Standard workflow:
- A Lambda function calls Amazon Textract to extract the invoice fields.
- A Choice state checks the amount. Invoices over $10,000 wait for manager approval (a task token pauses the workflow for up to days).
- The approved invoice is written to DynamoDB and an
InvoiceApprovedevent is published to a custom bus. - Other teams react independently: the finance system gets an SQS message, and the analytics team's Firehose stream archives the event. A Catch state sends failures to an SNS alert and a DLQ.
Because the services only exchange events, the finance team added a new consumer without altering the pipeline, and every execution is auditable through the Step Functions history.
Architecture Diagram
S3 emits events to EventBridge, which starts a Step Functions workflow and fans out results.
- 1A supplier uploads a PDF and S3 emits an Object Created event to EventBridge.
- 2The rule matches the event pattern and starts a Step Functions execution.
- 3The workflow extracts data with Lambda, waits for approval if needed, and stores the result in DynamoDB.
- 4A final event is published; downstream consumers such as the finance queue react independently.
Best Practices
- ✓Prefer EventBridge for routing AWS and SaaS events with content filtering instead of custom polling code.
- ✓Buffer slow consumers with SQS and attach DLQs to rule targets and Lambda async invocations.
- ✓Design idempotent handlers and include a unique event ID so duplicates are safe.
- ✓Use Step Functions for multi-step logic instead of chaining Lambda functions that call each other.
- ✓Define event schemas (Schema Registry / versioned detail-type) to avoid breaking consumers.
- ✓Use separate custom buses per domain and share them cross-account via resource policies.
- ✓Enable archive and replay on critical buses to recover from bugs and rebuild state.
- ✓Monitor failed invocations, throttles and DLQ depth with CloudWatch alarms; trace with X-Ray.
Common Interview Questions
Exam Tips
SAA-C03 focus
- "React to AWS service events (EC2 state change, GuardDuty finding, S3 upload)" -> EventBridge.
- CloudWatch Events = EventBridge (same service; EventBridge is the newer name with extra features).
- Scheduled tasks (cron) without servers -> EventBridge rule/Scheduler + Lambda.
- Multi-step workflow, retries, human approval, branching -> Step Functions. Up to 1 year -> Standard.
- Ordered, replayable, real-time data stream with multiple consumers -> Kinesis Data Streams (not SQS).
- Integrate third-party SaaS events (e.g. Zendesk, Datadog) -> EventBridge partner event source.
- Migrating on-premises apps using JMS/AMQP/MQTT -> Amazon MQ, not SQS/SNS.
- Lambda failures on async invocation -> configure on-failure destination or DLQ (SQS/SNS).
Chapter quiz
Application Integration · 5 questions
1.A company's web application writes orders directly to a processing service. During sales events the processing service becomes overloaded and orders are lost. Which change MOST effectively fixes this with the least operational overhead?
2.A banking application must process transactions for each account strictly in the order they were submitted, and no transaction may be processed twice. Which solution meets this?
3.An order service must notify billing, shipping and analytics systems whenever an order is placed. Each system processes at a different speed and must not lose messages if it is temporarily down. What is the BEST design?
4.A company wants to automatically start a multi-step approval workflow, which can pause for several days waiting for a manager, whenever a PDF is uploaded to an S3 bucket. Which combination should a solutions architect use?
5.Messages in an SQS queue are occasionally processed by two consumers at the same time because processing takes about 90 seconds. The queue uses default settings. What should the architect change?
0 of 5 answered
Finished this lesson?
0 of 64 lessons done · 0% of the course

