In this lesson · topic 6 of 7
Topic 6
When the undo cannot be done
4 min read
An undo is a call like any other
A refund goes through the same network as the charge. It can time out, hit a down service or be refused. The saga cannot leave the order half done, so it retries.
Retries are only safe if the compensation is idempotent. Give each one a key made from the saga id and the step. A second try then returns the first result, and does not refund twice.
Giving up
A retry that never succeeds must have a limit. In the lab, a compensation is tried again up to 4 timesmeasured, and then the saga is parked. At the defaults, 0 sagasmeasured were parked. With half of all undos failing, 3 sagasmeasured were.
A parked saga is a bug report for a person or a repair job. It holds partial state, such as a charge with no refund. Count parked sagas, track their age and alert on them. The count is a direct measure of how well your compensations work.
One more case
A compensation can arrive for a step that never ran, because the request to run it was lost. The undo must notice that there is nothing to cancel, record that fact, and succeed. If the original request arrives late, it must see the record and refuse to run.
Predict first