MicroservicePatterns.com

Suggestions

  • PagePattern catalogAll patterns by category.
  • LabCircuit Breaker and Retries labCrash a dependency and tune the breaker.
  • LabSaga labFail a step and watch the compensations run.
  • PagePractice questionsScenario questions with explanations.
  • PageDesign reviewCheck your own architecture for anti-patterns.
Data management

Saga Lab

Place an order that needs four services to agree, with no shared transaction to hold it together. Make a step fail and watch the saga undo the steps that already happened, then add the problems real systems have: a missing refund, duplicate messages, a compensation that fails.

Background: Saga, Transactional Outbox, Idempotent Consumer.

Scenarios
Coordination

One orchestrator tells each service what to do and tracks the saga's progress.

Failure
Real-world problems
Step 0 of 9
–Order status
0Items reserved
$0Customer charged (order $50)
–Courier
OrchestratorOrderInventoryPaymentShipping
CommandReply or local stepFailureCompensationDuplicate delivery
Guided experiments

Run these in order

  1. Watch the happy path

    Load it. Each step is a local transaction in one service. No lock is held across services, so between steps other requests can see the order as pending.

  2. Fail the last step

    Shipping finds no courier. The saga undoes what already happened, newest first: refund, release the item, cancel the order. Shipping itself has nothing to undo.

  3. Forget a compensation

    Payment has no refund step. Everything else is undone, but the customer has paid for a cancelled order. Every step that changes something needs its undo designed up front.

  4. Deliver messages twice

    Brokers deliver at least once, so duplicates happen. Without idempotent handlers the refund runs twice and the item is released twice. Then tick “Handlers ignore duplicates”. Cancelling is safe either way: setting a status twice changes nothing.

  5. Let a compensation fail

    The refund times out and nobody retries. The orchestrator stops, leaving the order pending and the item reserved until a person steps in. Tick “Retry failed compensations”: compensations must be retried until they succeed.

  6. Compare with choreography

    Switch the coordination to choreography and rerun the timeout. Each service reacts to events on its own, so the others still undo their steps. But no service knows the saga as a whole is stuck, which is why choreography needs good tracing.

This lab simplifies reality on purpose. Messages arrive in order and nothing runs in parallel. Real sagas also have to handle other requests that read half-finished data (for example, stock that is reserved but not yet paid for), messages that arrive out of order, and timeouts where a step's result is unknown. Frameworks such as Temporal, Camunda and AWS Step Functions handle the retries and saga state for orchestration.