Try
↑ ↓ move↵ openesc close

Interview prep / Sagas

Senior · Sagas · System design interview question

When would you choose a saga over two-phase commit, and when the reverse?

Sketch your own answer first, then compare it with the one below.

A strong answer

Choose a saga when the steps are in separate services or organizations, take long, or call things that cannot join a transaction, such as a payment provider. A saga holds no locks across steps, so one slow step does not block others, and no service waits for a coordinator.

Choose two-phase commit when the participants are databases under one team, the transaction is short, you need real isolation, and compensation would be awkward. A money transfer between two shards of one store is an example.

The trade-off is isolation against availability. Two-phase commit gives strong isolation and blocks. A saga stays available and makes the application deal with the anomalies.

Sources

Learn it by running it

The sagas and compensation lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

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