Skip to content
Prompt Words
History Member

Saga

Also called: saga pattern.

A way to do one business action across several services, each with its own database, as a chain of steps. Each step commits on its own, so there is no rollback across them. If a later step fails, the saga runs an undo step (a compensation) for each step that already worked, usually newest first, so nothing is left half-done.

Each service saves its own step in its own database, so nothing can roll all three back. When a step fails, the trip service undoes the steps that worked, usually newest first.

Booked: 0 · Cancelled: 0 · Half-done: 0

No trip yet. Book a trip to see the 3 steps, or book when flights are full to see them undone.

    No trip yet

    Say it in a prompt

    Book trips as an orchestrated saga in the trip service: reserve the hotel, put a $480 hold on the card with Stripe, book the flight, and only then capture the payment. Put steps that can't be undone last. If a step fails, run the compensations in reverse order: release the hold, then cancel the hotel. Save the saga's state in a trip_sagas table after every step, retry each compensation until it succeeds, and send every call with an idempotency key made of the trip ID and the step.

    Vague vs precise prompt

    Vague prompt

    book the hotel, payment and flight together

    Typical resultCalls the three services one after another in one request handler and charges the card first. When the flight call fails, the money is taken and the room stays reserved, and someone has to fix it by hand.

    Precise prompt

    Run the booking as a saga: reserve the hotel, hold $480 on the card, book the flight, then take the money. If a step fails, release the hold, then cancel the hotel, retrying each undo until it succeeds.

    Typical resultA full flight ends with the trip cancelled, the hold released and the room freed, with no money taken, and the trip_sagas table shows which step each trip reached.

    Seen on

    • microservices.io: Describes a saga as a sequence of local transactions in different services; if one fails, compensating transactions undo the changes the earlier ones made. A saga is coordinated either by choreography (events) or by an orchestrator.
    • Azure Architecture Center: The saga pattern page: each local transaction commits in its own service, compensating transactions reverse the completed steps when a later one fails, steps should be idempotent so they can be retried, and a compensation can fail too.

    You might describe it as

    • release the card hold if the flight can't be booked
    • a booking across several services that cancels cleanly
    • each service takes back its own part when a later step fails

    Not to be confused with

    • Durable workflow

      A saga is a pattern, a chain of steps with an undo for each; a durable workflow is a job whose engine remembers which steps are done, and sagas are often built as one.