Hedronite · Cert-Prep Lesson · AWS SAP-C02 + DOP-C02 · Tue 2026-06-30

AWS Event-Driven State Machines for Sequenced Gates

Step Functions, EventBridge Scheduler, and the idempotent confirmation store across SAP and DOP.

Lesson Class: Cert-Prep (AWS SAP-C02 + DOP-C02)
Cycle: W3/C2 · Tuesday (AWS combined)
Word Count: ~2,420
Paired Ops: Multi-Signal Exit Confirmation for Market-Regime Withdrawal
Paired Dev: Python enum and a Guarded State Machine
Grounding: Kleppmann DDIA Ch 11 p 483 · Akidau Streaming Systems Ch 5 p 172 · Reis & Housley FoDE p 120
Discipline: ROD v3 (universal-application)

A workflow that waits days for an external signal and must survive a reboot — where should its memory live?

The Ops lesson built a four-leg exit protocol. The Python lesson encoded it as a guarded state machine. This lesson runs that machine on AWS, where the legs become Step Functions states, the daily signal arrives from a scheduler, and the fake-reversal filter becomes an idempotent write to a DynamoDB conditional store. SAP asks how to architect it for availability and cost; DOP asks how to deploy, observe, and recover it.

§ IFrame

A sequenced confirmation gate is a long-running workflow. It spans days, waits for external signals, and must survive a process restart without losing its place. Holding state in memory is the wrong architecture on AWS — a Lambda times out, an EC2 instance reboots, and the sequence is lost. The right architecture externalizes the state into a managed service that persists the position and resumes exactly where it left off.

AWS Step Functions is that service. A state machine definition in Amazon States Language holds the legs as states, the transitions as Next fields, and the wait-for-signal behavior as task tokens. The workflow's position lives in the service, not in any compute instance. This is the architectural point both exams test from opposite sides.

§ IIDomain Foundations

Event-driven workflow as the shared foundation

An event-driven architecture decouples the producer of a signal from the consumer that acts on it. Reis and Housley frame the pattern (Fundamentals of Data Engineering, Part I, p. 120): events flow through a broker, and consumers react without the producer knowing who reacts. The exit gate is event-driven by nature — the ETF flow publication, the stablecoin inflow reading, and the price reclaim arrive on different clocks, and the workflow reacts to each as it lands.

The hard part of any event-driven gate is exactly-once handling. Kleppmann's treatment of stream-processing fault tolerance (Designing Data-Intensive Applications, Ch 11, p. 483) is the foundation: when a consumer can crash and retry, the same event may be delivered more than once, and the system must produce the same result as if it were delivered once. Akidau sharpens it (Streaming Systems, Ch 5, p. 172): true exactly-once delivery is impossible, so systems achieve exactly-once effects through idempotent operations keyed on a deduplication identifier. This is the fake-reversal filter at the infrastructure layer — a redelivered publication must not count as a second confirming print.

§ IIISAP Flavor — Architecting for Availability and Cost

SAP-C02 · Solutions Architect Professional

Standard versus Express workflows. Standard workflows run up to a year, are durable, and bill per state transition. Express workflows run up to five minutes and bill on duration and memory. A multi-day exit gate is a Standard workflow without question — the durability and long runtime are the requirement, and the low transition count makes the per-transition cost trivial.

The wait pattern. A leg that waits for a daily publication should not poll. The architecture uses the task-token integration: the machine pauses at a .waitForTaskToken task, an EventBridge rule fires when the publication lands, a Lambda validates the signal and calls SendTaskSuccess or SendTaskFailure with the token. The workflow consumes zero compute while it waits — no idle instances, no polling bill, managed durability.

The confirmation store. The idempotent confirmation lives in DynamoDB. Each write uses a conditional expression keyed on (leg, publication_date) so a redelivered event fails the condition and is absorbed. On-demand capacity suits the bursty, low-volume pattern, and a global table gives multi-region durability if the gate must survive a regional event.

§ IVDOP Flavor — Deploying, Observing, Recovering

DOP-C02 · DevOps Engineer Professional

Deploying the definition. The state machine is infrastructure. Its ASL definition ships as code through CloudFormation or the CDK, version-controlled, deployed through a pipeline. A change to a leg's threshold is a code change with a review and a deploy, not a console edit.

Observing the execution. Step Functions emits execution history natively, and every transition is a CloudWatch event. The instrumentation routes execution-status changes to EventBridge, alarms on ExecutionsFailed, and ships history to CloudWatch Logs for audit. A gate that advances to a leg it should not have reached is detectable because every transition is a logged, queryable event. This reaches back to the 06-23 CloudTrail Lake lesson — the same audit-first posture, now applied to workflow transitions.

Recovering a stuck execution. A leg waiting on a task token can hang if the token-holder never responds. The discipline sets HeartbeatSeconds and TimeoutSeconds on the wait task so a stuck leg fails into a Catch state rather than waiting forever. The Catch block routes the failure to a recovery branch that resets the leg — the cloud expression of the Python machine's reset edge.

§ VWorked Scenario

A flow publication lands and triggers the gate. EventBridge matches the event and invokes the validator Lambda. The Lambda writes the signal to DynamoDB with a conditional put keyed on (FLOW, 2026-06-30).

PutItem
  TableName: exit-confirmation-store
  Item: {leg: FLOW, pub_date: 2026-06-30, positive: true, funds: 2, inflow_usd: 90000000}
  ConditionExpression: attribute_not_exists(pub_date)

If the publication is delivered twice by a retry, the second PutItem fails the attribute_not_exists condition and the Lambda treats it as a successful no-op. The leg counts one confirming print, not two. The idempotent store is the fake-reversal filter's infrastructure twin: it refuses to let a redelivery masquerade as a second observation.

The Lambda then reads the leg's confirmation count. If Leg 1 has now seen two genuine consecutive publications, it calls SendTaskSuccess and the workflow transitions from the flow-wait state to the capital-wait state. If the count is one, the Lambda calls nothing and the workflow stays paused, costing nothing, until tomorrow's publication. A failed print calls SendTaskFailure, the Catch block resets the leg, and the workflow returns to the held-regime state.

Cross-Exam Seam — One Machine, Two Lenses SAP and DOP are not two systems. They are two readings of one Step Functions workflow. SAP picks Standard-vs-Express and the wait pattern for cost and availability; DOP wires the same definition through a pipeline, alarms its transitions, and sets the timeouts that recover it. Study the architecture once; answer both exams from it.

§ VIConnection to Today's Ops + Dev Lessons

The Ops lesson defined the four legs and the rule that none clears out of order. The Python lesson encoded that as a transition table where illegal moves are absent edges. This lesson runs the same machine as a Step Functions Standard workflow: the ASL Next fields are the table's edges, the .waitForTaskToken tasks are the legs waiting on signals, the DynamoDB conditional put is the confirmation counter's deduplication. Three lessons, one machine at three altitudes — trading logic, in-process encoding, managed cloud execution.

§ VII · Practice Questions
Question 1 · Workflow type
A confirmation workflow must run up to three weeks, survive instance failures, and wait days between signals while consuming minimal compute. Which Step Functions configuration fits?
B is correct. Standard workflows run up to a year with durable state; task-token waits consume no compute and resume on an event. Express workflows cap at five minutes (eliminating A and C). A polling loop (D) bills for transitions it does not need.
Question 2 · Idempotency
A flow publication event is occasionally delivered twice by an at-least-once broker. The gate must not count the redelivery as a second confirming signal. Which mechanism enforces this?
B is correct. A conditional put keyed on the deduplication identifier makes the write idempotent — the redelivery fails the condition and is absorbed. SQS content-dedup (A) only spans five minutes. Reserved concurrency (C) limits parallelism, not duplicates. A schedule (D) does not dedup event-driven deliveries.
Question 3 · Recovery
A leg waits on a task token, but the validator that should return it crashes and never responds. Without intervention the workflow waits indefinitely. Which configuration recovers it?
B is correct. The wait task's own timeout and heartbeat fail the state into a Catch branch that runs recovery. A validator timeout (A) does not release a token already requested. An alarm (C) notifies but does not recover. A TTL (D) expires data, not a stuck execution.
Question 4 · Change discipline
The DOP team must treat a change to a leg's threshold as a reviewable, versioned change. Which practice satisfies the exam's expectation?
B is correct. Infrastructure-as-code with pipeline review makes the definition a versioned artifact with a change history. Console edits (A, C) leave no review trail. A wiki (D) is not enforced configuration.
Question 5 · Multi-region durability
For multi-region durability of the confirmation store so the gate survives a regional event, which DynamoDB feature applies?
B is correct. Global tables give active-active multi-region replication with the durability the gate needs. DAX (A) is a cache. Nightly backups (C) lose intra-day writes. DynamoDB has no read-replica construct (D); that is an RDS concept.

§ VIIIClosing

The exit gate is a long-running, event-driven, fault-tolerant workflow, and AWS has a service shaped exactly to that sentence. Step Functions Standard holds the sequence, EventBridge delivers the signals, DynamoDB conditional writes enforce idempotency, and Catch blocks recover the stuck legs. SAP designs it for availability and cost; DOP deploys, observes, and recovers it. Same machine, two exams, one architecture.

Draw the state machine before you draw the diagram. The legs are the states; the rest is plumbing.

🫡 ⚖️ 📜
Leo.Syri — Praetor Consulate, Imperium Luminaura
Lesson filed: 2026-06-30 · Cert-Prep/AWS · Tuesday W3/C2
Prior arc: AWS Data Protection — WORM + Audit Stack (2026-06-23) · Grounding: Kleppmann DDIA Ch 11 p 483