Skip to content
CloudDIFFICULTY: AdvancedSTATUS: Prototype

Distributed Sagas: Fault-Tolerant Order Processing

Compensating Transactions with Step Functions

GitHub Repository
Client / ScopePersonal Lab Build
My RoleSole Developer
Duration—
Completion Date—

1. SYSTEM OVERVIEW

Executive Summary

A saga-based order processing system on Step Functions implementing idempotent operations, bounded retries, compensating actions, manual repair procedures, failure testing, and a transactional outbox over DynamoDB Streams to close the write/publish gap.

Business Problem

Distributed orders fail halfway: payment taken but inventory unreserved, with no consistent way to roll forward or back.

Business Impact Value

Shows the patterns that make distributed transactions safe: each step has a compensating action, retries are bounded, and nothing is left half-done without a repair path.

Key Engineering Goals
  • Model order processing as a saga with explicit compensating actions
  • Make every operation idempotent with bounded retries
  • Close the database-write/event-publication gap with a transactional outbox
My System Responsibilities
  • Designed the saga steps, compensations, and retry policies
  • Implemented the DynamoDB Streams transactional outbox
  • Built failure test scenarios including manual repair flows

2. SYSTEM FEATURES

Saga OrchestrationComplexity: High

Order steps run in sequence with a defined compensation per step.

Impl:Step Functions with catch blocks routing to compensating states.
Transactional OutboxComplexity: High

Database writes and event publications stay consistent.

Impl:Outbox table tailed by DynamoDB Streams to publish exactly-once-ish events.
Manual Repair ProceduresComplexity: Medium

Unrecoverable states land in a repair queue with operator steps.

Impl:Documented repair flow plus failure-scenario test suite.

3. SYSTEM ARCHITECTURE

Orchestrated saga: forward steps with paired compensations, plus an outbox so side effects publish reliably after the write commits.

Topology Vector Diagram
Order API ──> Step Functions Saga ──┬──> Reserve ──> Charge ──> Confirm
                                    │
                    [failure] ──> Compensate (reverse order) ──> Repair Queue
                                    │
              DynamoDB Outbox ──> Streams ──> Event Publication
Pipeline flow sequences
Order request starts the saga execution
Each step executes idempotently with bounded retries
On step failure, completed steps compensate in reverse order
State changes and outbox rows commit together
DynamoDB Streams publishes outbox events downstream
Repo directory structure
saga-orders/
├── saga.asl.json              # State machine definition
├── src/
│   ├── steps/                 # Forward operations
│   ├── compensate/            # Compensating actions
│   └── outbox.py              # Outbox publisher
└── tests/
    └── failure_matrix.md      # Failure scenarios + repairs

4. INTERACTIVE SIMULATOR WIDGET

Run active operations audits utilizing the custom sandbox telemetry receiver widget below.

No interactive widget available for this system configuration.

5. ENGINEERING ARCHITECTURE DECISIONS (ADRs)

Decision ProfileChoose saga coordination style
Context

Steps span services with no shared transaction; failures must unwind predictably.

Alternatives Checked
  • Choreography via events
  • Orchestrated saga via Step Functions
  • Two-phase commit
Selected Decision

Orchestrated saga via Step Functions

Advantages
  • One readable definition of order and compensation flow
  • Retries, timeouts, and error paths are explicit
  • Execution history doubles as an audit trail
Disadvantages
  • Orchestrator is a central coupling point
  • State transition costs per step
Trade-off details

Accepted centralization for explicitness and auditability.

Future Scaling direction

Extract the outbox publisher into a shared construct for other services.

6. DETAILED TECHNOLOGY STACK

cloud
• AWS Step Functions• AWS Lambda• Amazon DynamoDB• DynamoDB Streams
testing
• Failure Injection Scenarios

7. SECURITY REVIEW & POSTURE

Idempotency as Safety

Retried steps must never double-charge or double-reserve.

Mitigation StrategyIdempotency keys on every mutating operation, verified in failure tests.

9. ENGINEERING CHALLENGES & RESOLUTIONS

Vulnerability Bottleneck

The gap between writing to the database and publishing the event.

Root Cause:Crash between the two leaves state and notifications inconsistent.

System Investigation

Walked through crash points in the saga and found the dual-write window.

Engineering Solution

Transactional outbox: write state and outbox row atomically, publish via DynamoDB Streams.

Trade-offs accepted

Adds a table and a publisher component to operate.

Lessons Derived

In distributed systems, "write then publish" is a bug waiting for a crash.

10. SYSTEM LESSONS LEARNED

Engineering Lessons

Compensations deserve the same design rigor as forward paths.

Architecture Lessons

Orchestration makes complex failure handling legible.

Business Lessons

Customers experience rollbacks as reliability when they are clean and communicated.

System Redesign Plans

I would add saga execution dashboards showing live compensation activity.

11. ROADMAP & TECHNICAL DEBT

  • Live saga monitoring dashboard
  • Shared outbox construct for reuse
  • Chaos-style randomized failure drills

12. GITHUB SOURCE EXPLORER

Audit raw repository script configurations directly inside the active terminal workspace.

HarizuAru/Portfoliomain
Open on GitHub
Workspace Files
1
Encoding: UTF-8Lines: 1
Let's discuss your project

Interested in building a secure auto-scaling platform similar to this?

Keep exploring

Related Projects

All projects →
Cloud · DevOpsPrototype

Cloud-Native Serverless Architectures

A multi-cloud serverless deployment leveraging AWS Lambda, DynamoDB, and Azure Functions to build scalable pipelines that minimize operational overhead.

ArchitectureAPI Gateway → Lambda / Azure Functions → DynamoDB / CosmosDB

  • aws
  • azure
  • serverless
  • dynamodb
  • terraform
Security · Cloud · DevOpsPrototype

Automated Incident Response (SOAR) Pipeline

A security orchestration pipeline that detects unauthorized EC2 security group modifications via EventBridge, orchestrates response with Step Functions, isolates instances with Lambda, captures EBS forensic evidence, and publishes reports to SNS.

ArchitectureEventBridge → Step Functions → Lambda → EBS Snapshots → SNS

  • aws
  • eventbridge
  • step-functions
  • lambda
  • sns
Cloud · DevOpsPrototype

Distributed Queue Worker Operations

A production-style distributed queue processing system: a Lambda worker drains DynamoDB orders from SQS with structured correlation logging, multi-dimensional CloudWatch monitoring, SNS alert routing, injected failure drills, and runbook-driven recovery measured against SLOs.

ArchitectureSQS → Lambda Worker → DynamoDB → CloudWatch → SNS Alert Queue

  • aws
  • sqs
  • lambda
  • dynamodb
  • cloudwatch