Nebo15 / sage

A dependency-free tool to run distributed transactions in Elixir, inspired by Sagas pattern.
MIT License
912 stars 40 forks source link

Question around `0.6` upgrade compensations #55

Closed coladarci closed 4 years ago

coladarci commented 4 years ago

Hey! I'm super pumped to see this upgrade as I know a lot had built up in master.

While I'm excited to see that compensations should no longer have knowledge of failed steps, there are quite a few compensations in my old code where I was doing something like this:

def revert(_sc, effects, {:raise, _exception}, _attrs), do: ...

i.e if something were to raise downstream, I still have to compensate.

I think I can still act on this by checking at all the effects so far and an absence of a given stage probably means it either didn't get there or that stage raised? Feels brittle - just curious if you have a recommended pattern here that you had in mind when removing this info from the compensations.

Thanks!

coladarci commented 4 years ago

I should also note, this isn't just about the raise scenario - it appears all errors are ignored; I sort of thought I'd have access to what every stage returned, even if it was an {:error, something}. This might be a blocker for my upgrade as there are my compensation does depend on the nature of the failure down stream.

coladarci commented 4 years ago

I'm going to go ahead and close this - while the refactor caused me to have to really re-think my compensations, it lead to a much better design. I 100% stand w/ your stance here that compensations shouldn't have intimate knowledge about other stages - in our case we just had to move some of the logic out of the Saga completely, but that was a much better design decision anyhow. Appreciate it and you!