jargon

Comparison

SagavsTwo-phase commit

Saga

you break the cross-service operation into local transactions and write an undo step for each one, because there is no shared rollback.

A sequence of local transactions across services, with a compensating action for each step, so that a failure part-way is unwound rather than rolled back. It buys availability and loose coupling at the cost of never having true atomicity: intermediate states are visible, and compensation is not the same as undo. Every saga step must be idempotent, because retries are guaranteed.

CoordinatorService AService Bstep 1donestep 2failedundo step 1
Full entry →

Two-phase commit

you ask both databases to prepare, wait for both to say yes, and only then tell both to commit.

A protocol for making one transaction span multiple resources: a prepare round, then a commit round once all participants agree. It gives atomicity across systems and takes availability in exchange — if the coordinator dies between phases, participants sit blocked holding locks. This is why distributed systems mostly prefer sagas to 2PC.

CoordinatorService AService Bprepareprepareyesnoabortabort
Full entry →

Related comparisons