I want to show library I’m working on: Sage. It’s a dependency-free implementation of Sagas pattern in pure Elixir. It’s intended to simplify dealing with distributed transactions, especially with an error recovery/cleanup. Sage guarantees that either all the transactions in a saga are successfully completed or compensating transactions are run to amend a partial execution.
Elevator pitch is: “Sage is an
Ecto.Multi for your business logic”.
With Sage you can do something like this:
import Sage new() |> run(:user, &create_user/2, &delete_user/3) |> run(:plans, &fetch_subscription_plans/2) |> run(:subscription, &create_subscription/2, &delete_subscription/3) |> run_async(:delivery, &schedule_delivery/2, &delete_delivery_from_schedule/3) |> run_async(:receipt, &send_email_receipt/2, &send_excuse_for_email_receipt/3) |> run(:update_user, &set_plan_for_a_user/2, &rollback_plan_for_a_user/3) |> finally(&acknowledge_job/2)
There are interesting papers I’ve used to get ideas for building it: