Try
↑ ↓ move↵ openesc close

Curriculum · Module 08, Distributed Transactions

Lesson 2 · 7 topics · 31 min · Intermediate · 0/7 done

Sagas and compensation

Split one big transaction into local steps and undo with new steps when one fails. Orchestration and choreography coordinate them, and readers can see the middle.

What each topic covers

  • A locked transaction across services is slow and fragile. A saga trades the lock for a way to take a step back.
  • Each step has a compensating action. When a step fails, the saga runs the undos of the finished steps, last first.
  • Run sagas with failing steps and undos, switch coordination style, and turn a semantic lock on and off.
  • Sagas give up isolation. Readers can see steps that are later undone, and a long saga fails more often than a short one.
  • Orchestration puts the flow in one place and costs messages. Choreography has no owner and is hard to follow.
  • A compensation can fail too. Retry it safely, then park the saga for a person.
  • Three quick checks on what a compensation is, what a saga does not give you and how the two styles differ, with the sources behind the lesson.

Topics

  1. 1An order that spans four services3 min
  2. 2Steps, undos and the reverse order4 min
  3. 3Fail steps and watch readers see the middle8 min
  4. 4Atomic in the end, visible in the middle5 min
  5. 5One conductor or a chain of events4 min
  6. 6When the undo cannot be done4 min
  7. 7Compensation, isolation and coordination3 min

Practise this lesson

8 interview questions on sagas, with worked answers and sources.

Practise these

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms