CURRICULUM PREVIEWRevision 1 · Open for reviewReview the full course
OPTIONAL EXPLORATION10 min read

Saga and compensation

Coordinate a business process across local transactions.

Before you begintransactional-outbox

The problem and the pattern

A booking workflow may reserve capacity, request payment, then confirm the reservation. If payment fails, release capacity through an explicit compensating action. A saga records progress and recovery decisions. Compensation is a new business action; it is not a database rollback across services.

Follow the flow

Make it concrete

This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.

Focused example
text
Reserve capacity → request payment → confirm booking
Payment fails → release capacity
Payment outcome unknown → reconcile before retrying charge

Trade-offs

  • Long-running workflows become observable and recoverable.
  • Compensation can fail and needs its own retries and escalation.
  • Business stakeholders must define acceptable intermediate states.

When to avoid it

Avoid sagas for work that fits safely into one local database transaction.

Your turn

Payment times out after the provider may have charged the card. Why is immediately charging again dangerous?

Reveal a worked answer

A timeout does not prove failure. Reconcile using the provider operation ID or idempotency key, then decide whether to retry or compensate. Persist workflow state and make each step repeatable.

Keep exploring

One more piece connected.

Mark this lesson complete when you can explain the idea.