teluzia.Cloud Engineer · Day 68
CHAPTER 10 · SERVERLESS AND MESSAGING

EventBridge and Step Functions

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

EventBridge is a sorting desk for events; Step Functions is the checklist that coordinates a multi-step business process after work starts. EventBridge receives structured events and matches them against rule patterns. Matching events go to configured targets; event content is data, not an instruction to execute arbitrary code. Rules can select source, detail-type, and fields inside detail. Delivery retry and dead-letter settings help protect targets from transient failures. Step Functions represents workflow control as explicit states and transitions. A Task delegates work, Choice branches, and other state types coordinate timing or parallelism. Standard and Express workflows have different execution and billing characteristics. Select the type from duration, auditability, integration needs, and execution semantics rather than familiarity.

Think of it this way

EventBridge is a sorting desk for events; Step Functions is the checklist that coordinates a multi-step business process after work starts.

TOPIC 01 / 03Step by step

Event buses, rules, and patterns

EventBridge receives structured events and matches them against rule patterns. Matching events go to configured targets; event content is data, not an instruction to execute arbitrary code. Rules can select source, detail-type, and fields inside detail. Delivery retry and dead-letter settings help protect targets from transient failures. For example, match source com.shop and detail-type OrderCreated, then route only orders whose detail.region is eu to an appropriate processing target.

WORKED EXAMPLE
Match source com.shop and detail-type OrderCreated, then route only orders whose detail.region is eu to an appropriate processing target.

A payment service emits an event with source com.store.payments, detail-type PaymentSettled, and a detail object containing currency and orderId. EventBridge receives it on a bus and evaluates configured rule patterns. One rule targets finance processing for a selected currency; another targets order completion. The publisher need not call either consumer directly.

An event bus receives events. A rule connects a matching pattern to targets. An event pattern tests selected fields using EventBridge's matching rules rather than executing arbitrary expressions from the payload. Develop examples before attaching a target: a matching event, a wrong source, and a missing required field. A target may receive a transformed payload, so test that mapping too. Delivery can fail after a successful put-event request, requiring target retries and dead-letter handling. Event routing creates flexible coupling, but schema drift can silently remove expected matches unless contract tests and observability identify accepted events that never reach intended consumers.

Why this matters

Clear event schemas and narrow matching rules make routing reviewable and keep unrelated events from unexpectedly triggering costly or privileged downstream workflows in production.

A common trap

Treating a pattern as a full JSON equality comparison misses EventBridge matching semantics; test sample matching and nonmatching events before connecting a live target.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Event buses, rules, and patterns

EventBridge receives structured events and matches them against rule patterns. Matching events go to configured targets; event content is data, not an instruction to execute arbitrary code. Rules can select source, detail-type, and fields inside detail. Delivery retry and dead-letter settings help protect targets from transient failures. For example, match source com.shop and detail-type OrderCreated, then route only orders whose detail.region is eu to an appropriate processing target.

WORKED EXAMPLE
Match source com.shop and detail-type OrderCreated, then route only orders whose detail.region is eu to an appropriate processing target.

A payment service emits an event with source com.store.payments, detail-type PaymentSettled, and a detail object containing currency and orderId. EventBridge receives it on a bus and evaluates configured rule patterns. One rule targets finance processing for a selected currency; another targets order completion. The publisher need not call either consumer directly.

An event bus receives events. A rule connects a matching pattern to targets. An event pattern tests selected fields using EventBridge's matching rules rather than executing arbitrary expressions from the payload. Develop examples before attaching a target: a matching event, a wrong source, and a missing required field. A target may receive a transformed payload, so test that mapping too. Delivery can fail after a successful put-event request, requiring target retries and dead-letter handling. Event routing creates flexible coupling, but schema drift can silently remove expected matches unless contract tests and observability identify accepted events that never reach intended consumers.

Why this matters

Clear event schemas and narrow matching rules make routing reviewable and keep unrelated events from unexpectedly triggering costly or privileged downstream workflows in production.

A common trap

Treating a pattern as a full JSON equality comparison misses EventBridge matching semantics; test sample matching and nonmatching events before connecting a live target.

State machines and state transitions

Step Functions represents workflow control as explicit states and transitions. A Task delegates work, Choice branches, and other state types coordinate timing or parallelism. Standard and Express workflows have different execution and billing characteristics. Select the type from duration, auditability, integration needs, and execution semantics rather than familiarity. For example, validate order -> Choice on valid -> reserve inventory -> charge -> complete; invalid orders follow a separate rejection branch.

WORKED EXAMPLE
Validate order -> Choice on valid -> reserve inventory -> charge -> complete; invalid orders follow a separate rejection branch.

A loan workflow first checks application data, then branches according to eligibility, calls a document service, waits for an approval callback where supported, and records a final result. Step Functions keeps that orchestration explicit rather than hiding the sequence inside one long-running function. The output of one state becomes input to subsequent processing according to the state's data handling configuration.

A state is one step or control decision. A transition identifies what happens next. A Task invokes work, while a Choice selects a branch from data. Standard and Express workflows differ in duration limits, execution semantics, supported patterns, observability, and pricing. Check those requirements before choosing. A state named Success does not establish that an external payment or database operation actually completed unless the Task contract and result prove it. Keep orchestration state separate from authoritative business records so operations can reconcile an execution with real data after interruption or an externally completed effect.

Why this matters

Explicit transitions make long-running workflows understandable and expose where business progress stopped, which is harder when coordination is hidden in nested handler calls.

A common trap

Confusing a state machine’s control state with durable business records can leave teams unable to reconcile external side effects after an execution fails.

Retry, catch, and compensation

Retry handles selected transient errors with bounded attempts and backoff; Catch directs handled failures to another state. Neither automatically reverses external effects. A workflow that reserves inventory then fails payment may need compensation to release the reservation. Every repeatable task still needs duplicate-safe behavior and a defined recovery contract. For example, retry a temporary dependency timeout three times, then Catch into a compensation task that releases the previously recorded inventory reservation.

WORKED EXAMPLE
Retry a temporary dependency timeout three times, then Catch into a compensation task that releases the previously recorded inventory reservation.

A workflow reserves two seats, then attempts payment. The payment service briefly times out. A bounded Retry can wait and retry selected transient errors, but repeated payment calls need a stable payment key. If payment ultimately fails, a Catch transition can route to a release-reservation operation using the reservation's recorded ID.

Retry repeats a failed state's work under specified conditions. Catch selects a recovery transition after an eligible failure. Compensation is an explicitly designed business action that addresses a previously completed effect; it is not automatic transaction rollback. Releasing seats may itself fail, so store enough information for later reconciliation and alert an owner. Distinguish a timeout with unknown payment outcome from a definite card rejection. The former may require querying payment status before retry or compensation. Bounded retries improve transient recovery, but indiscriminate retries multiply traffic, extend execution duration, and can turn a dependency outage into a larger incident.

Why this matters

Bounded recovery distinguishes temporary faults from permanent rejection and prevents retry storms while keeping partially completed business work visible to operators and customers.

A common trap

Retrying all errors indefinitely repeats validation failures and can duplicate charges; compensation must use recorded effect identifiers rather than guess what happened previously.

KEEP THESE WITH YOU

Today’s takeaways

Event buses, rules, and patterns: EventBridge receives structured events and matches them against rule patterns. Matching events go to configured targets; event content is data, not an instruction to execute arbitrary code. Rules can select source, detail-type, and fields inside detail. Delivery retry and dead-letter settings help protect targets from transient failures.

State machines and state transitions: Step Functions represents workflow control as explicit states and transitions. A Task delegates work, Choice branches, and other state types coordinate timing or parallelism. Standard and Express workflows have different execution and billing characteristics. Select the type from duration, auditability, integration needs, and execution semantics rather than familiarity.

Retry, catch, and compensation: Retry handles selected transient errors with bounded attempts and backoff; Catch directs handled failures to another state. Neither automatically reverses external effects. A workflow that reserves inventory then fails payment may need compensation to release the reservation. Every repeatable task still needs duplicate-safe behavior and a defined recovery contract.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed