Ash Resource Consistency Boundary vs Transactional Boundary

,

:wave: so you have a few options. Transactionality is built into Ash action. So using your chess game example, you might have something like this:

# on ChessGame

update :finish_game do
  change set_attribute(:complete)
  change fn changeset, _ -> 
    Ash.Changeset.after_action(changeset, fn changeset, game -> 
      # fetch players and modify their score
      # whatever happens here is transactional
    end)
  end
end

By default things that happen in hooks will be in the same transaction. You can also start your own transactions using Ash.DataLayer.transaction(resource, fn -> end)

If your resources are in the same data layer then this works exactly as you’d expect transactions to work. If you have resources across multiple data layers, a transaction for both will be opened. This makes it technically possible to achieve inconsistency if one transactions loses and the other one doesn’t due to a network error (for example). However, it makes a good effort at cross-data-layer consistency. There are usually some things to keep in mind if you are using cross data layer actions but I won’t go into that here because I don’t think that is the main thing in question :slight_smile: