What isolation anomalies can a saga show, and how do you reduce them?
Sketch your own answer first, then compare it with the one below.
A strong answer
Because each step commits at once, others see the middle. A reader can see a charge that a later failure refunds, a dirty read in effect. Two sagas can touch the same record, and one can overwrite what the other relied on, a lost update. A saga can also read one value twice and get two answers.
Countermeasures include a semantic lock, which is a pending flag that other code must respect. Commutative updates, so order does not matter. A pessimistic order of steps, so the hardest to undo comes last. Re-reading a value before a step relies on it, and versioning records.
Each one pushes work onto the application. Say that the saga's isolation is something you build, not something you get.
Sources
- Hector Garcia-Molina, Kenneth Salem (1987). Sagas.
- Chris Richardson (2018). Pattern: Saga.