Stage 4 · Provision
Asynchronous Systems
Workflow Orchestration
Temporal, Step Functions, sagas, and compensation steps for long-running business processes.
Why Workflow Orchestration?
Many business processes span multiple services and take minutes to hours: order fulfillment, insurance claims, loan approvals. These long-running processes need coordination, state management, retry logic, and compensation. Workflow orchestration platforms handle this complexity.
Saga Pattern
A saga is a sequence of local transactions where each step publishes an event that triggers the next step. If any step fails, compensating transactions undo the previous steps. Sagas provide eventual consistency without distributed transactions.
Order Saga:
1. Reserve inventory ✓
2. Process payment ✓
3. Create shipment ✗ (failed)
Compensation (reverse order):
3. N/A (shipment failed)
2. Refund payment ← compensate step 2
1. Release inventory ← compensate step 1
Result: System returns to consistent stateEach step in a saga has a corresponding compensation step. If any step fails, all completed steps are compensated in reverse order.
Temporal Workflows
Temporal is a workflow orchestration platform that uses code as workflows. You write normal code that Temporal executes durably — it survives crashes, retries, and server restarts. Temporal handles state management, retries, and compensation automatically.
AWS Step Functions
Step Functions is AWS's managed workflow service. Workflows are defined as JSON state machines. Each state can be a task (Lambda, ECS, SQS), a choice, a wait, or a parallel execution. Step Functions provides visual workflow monitoring and built-in error handling.
{
"StartAt": "ReserveInventory",
"States": {
"ReserveInventory": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123:reserve-inventory",
"Catch": [{
"ErrorEquals": ["States.ALL"],
"Next": "Failed",
"ResultPath": "$.error"
}],
"Next": "ProcessPayment"
},
"ProcessPayment": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123:process-payment",
"Catch": [{
"ErrorEquals": ["States.ALL"],
"Next": "CompensateInventory",
"ResultPath": "$.error"
}],
"Next": "CreateShipment"
},
"CompensateInventory": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:123:release-inventory",
"Next": "Failed"
},
"Failed": {
"Type": "Fail"
}
}
}Step Functions provides visual workflow execution, built-in retries and catches, and integration with 200+ AWS services. Good for simple to moderate workflows.
Compensation Steps
Compensation is the process of undoing completed steps when a later step fails. Compensation is not rollback — it is a new operation that reverses the effect of a previous operation. Compensations must be idempotent because they may be retried.
- Inventory reserve → Release inventory
- Payment charge → Refund payment
- Email sent → Send cancellation email
- Record created → Soft delete or mark as cancelled
Temporal provides full code flexibility, powerful retry logic, and local development. Step Functions is simpler for AWS-native workflows. Choose based on complexity and cloud strategy.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.