Retry work without charging twice
Separate simple message delivery from explicit process state, choose the correct Step Functions workflow type, and make retries, callbacks, compensation, and side effects duplicate-safe.
LESSON GOALS
By the end, you can
- Choose a queue or Step Functions workflow from process state, duration, branching, callback, and audit needs.
- Use bounded retries, idempotency keys, catches, and compensation without repeating irreversible side effects.
01
Separate delivery from process state
A queue answers “which worker should receive this job?” A workflow answers “which step is this business process in, and what happens next?” Do not add orchestration until the process needs explicit state.
List the states, branches, parallel work, waits, callbacks, compensation, duration, audit history, and volume. Independent jobs with the same retry policy may need only SQS workers. A payment that waits hours for a callback and may compensate needs a durable process record.
Separate transient failure from business rejection and poison input. A timeout may deserve retry. A declined payment should follow a nonretry branch. Malformed input may need quarantine and review.
Every retry needs matched errors, bounded attempts, backoff, and a timeout. Unlimited retries amplify an outage. Sending every first failure immediately to a DLQ gives up before a transient dependency can recover.
Idempotency remains required. A task can complete a charge and then time out before the workflow observes success. The next attempt must find the completed business result rather than charge again.
02
Choose Standard or Express from the boundary
Step Functions Standard workflows fit durable, long-running coordination, callbacks, and execution history. The four-hour payment callback belongs here because the process must wait and remain auditable.
Express workflows fit short, high-rate processing. Asynchronous Express uses at-least-once workflow execution; Synchronous Express uses an at-most-once boundary. Verify current duration and rate limits before choosing.
Those execution guarantees do not make an external side effect happen exactly once. A payment API, inventory update, or email can still complete before a timeout is observed. Each irreversible task needs its own stable operation key and stored result.
SQS stores work but not an end-to-end sequence of business states. EventBridge routes events but does not maintain callback and compensation state. A Lambda that sleeps or polls hides the process in runtime and makes recovery harder to inspect.
Choose the workflow type before polishing the state diagram. Duration, invocation semantics, history, and volume are deciding boundaries; a familiar visual editor is not.
03
Recover without repeating the side effect
Give each side effect an operation key tied to the business action, such as capture-order-482. Before executing, check whether that key already has a completed result. After success, persist the result where a retry can find it.
Use Retry only for errors that may recover. Keep attempts and total time bounded. Use Catch to send exhausted technical failure or a business rejection to the correct next state rather than treating every failure alike.
Compensation is a new business action, not a database rollback. Releasing reserved inventory after a failed payment can itself fail, so compensation also needs state, retry rules, and an owner.
For callbacks, bind a token to the expected order and caller, keep it out of logs, reject replayed or late callbacks, and time out the waiting state. A callback without authentication can advance the wrong execution.
Observe the branches separately: transient failure then success, business rejection, retry exhaustion, callback timeout, and compensation failure. Alarm on stuck or failed executions and retain enough context for review without exposing secrets.
For the payment scenario, Standard records the four-hour wait and every transition. A duplicate-injection test must show one charge for one operation key, while a failed downstream step enters compensation or review without losing the execution history.
DECISION TABLE
Compare the architecture constraints
| requirement | choose | because | reject |
|---|---|---|---|
| Hours-long callback and audit | Step Functions Standard | Durable state and duration decide | Express is short; SQS has no state machine |
| High-rate short async duplicate-safe workflow | Asynchronous Express | At-least-once semantics fit | Standard may add unneeded history |
| High-rate short synchronous no-duplicate execution | Synchronous Express | At-most-once boundary fits | Async Express is at-least-once |
| Independent retryable work | SQS workers | Handoff and redrive suffice | Step Functions adds unneeded orchestration |
GUIDED WORKED SCENARIO
Reason from the stated constraints
This is a guided example, not a question to memorise. The knowledge check uses new situations to test the same reasoning.
A payment waits up to four hours for callback, then captures inventory or compensates. Every transition is auditable; timeout after authorization must not charge twice.
Requirements
- Wait four hours for authenticated callback
- Retain history
- Retry without duplicate charge
- Compensate after bounded failure
Reasoning path
- Process has long-lived state and branches.
- Choose Standard due to duration and history.
- Use bounded Retry/Catch and timeouts.
- Use payment operation ID for idempotency.
Why it wins
- Standard supports long state and callbacks.
- Idempotency addresses partial completion.
Why the alternatives lose
It is short and at-least-once.
Becomes correct when: Workflow is short high-volume and duplicate-safe.Queue does not model callback and compensation.
Becomes correct when: Each item is independent work.Routing does not maintain process state.
Becomes correct when: Domains react independently without coordination.INTERACTIVE ARCHITECTURE VISUAL
Pick the workflow boundary, then inject a duplicate
Change process duration, workflow type, and payment idempotency. Execution semantics do not make an external charge happen once.
× Request stopsA four-hour auditable callback does not fit the short Asynchronous Express boundary.
Read the diagram as text
A state-transition table presents callback wait, transient retry, business rejection, compensation, operation key, and Standard-versus-Express decision.
KNOWLEDGE CHECK
Answer one question at a time
Pass every question to complete this lesson. Each answer includes reasoning before you continue.
KEY TERMS
Glossary
- Orchestration
- Explicit coordination of process states, tasks, branches, waits, and failures.
- State machine
- A model of allowed process states and transitions.
- Step Functions Standard
- A durable workflow type suited to long-running, auditable coordination and callbacks.
- Step Functions Express
- A workflow type for short, high-rate executions with subtype-specific semantics.
- Retry
- A bounded repeated attempt for a matching recoverable error.
- Catch
- A workflow transition that handles an error after matching or exhausted retries.
- Idempotency key
- A stable operation identifier used to prevent a repeated business side effect.
- Compensation
- A business action that offsets an earlier completed action.
- Callback
- A later authenticated signal that resumes a waiting workflow.
- Execution history
- The recorded states and transitions of one workflow run.
PRIMARY SOURCES
Verify the claims
- primaryAWS Step Functions Developer Guideaws-srv-step-functions · retrieved 2026-07-29
- primaryAmazon SQS Developer Guideaws-int-sqs · retrieved 2026-07-29
- primaryWhat is Amazon EventBridge?aws-int-eventbridge · retrieved 2026-07-29
- primaryStep Functions Workflow Typesaws-step-functions-workflow-types · retrieved 2026-07-30