2 phase commit on distributed elixir?

Let nodeA and nodeB be running on two different physical machines.

Suppose we need to both-commit or both-reject have them do

nodeA: Alice gains $1
nodeB: Bob loses $1

Is there a way for distributed elixir to solve this problem without the use of an external db ?

There is multiple ways to do so, each will have their own pros and cons. However in this case the easiest approach probably would be centralised ledger (with replication) and then instead of 2 separate actions:

  • Alice gains $1
  • Bob loses $1

You write 1 event:

  • Bob pays Alice $1

And then build state of both accounts by aggregating all events in the ledger.

3 Likes

I also did a 2-phase commit for similar banking transactions using Core library for Elixir and selective-receive technique.
You can find the code here: GitHub - hissssst/ex_banking: Test problem for coingaming

3 Likes