Have you considered using mnesia? It has transactions, hence locks for free. You don’t even need to store things in it, you can just use it to acquire locks inside transaction on a given “key” for an imaginary table? Although I think it would be a good option to store at least some things there (the current resources for each entity? even if after each transaction you would dump the changes somewhere else). Unless you’re really constrained in terms of memory you can probably store millions of rows in it before you have a problem.
Other option is to use the global module, it can be used to set locks as well, the lock can be any term ({starbase_id, :ore}) along with another term as reference to the process requesting the “lock” (worker_id for eg.). So when a worker receives the trade request, it would create a lock for the entity selling on the item it’s selling and another lock for the entity buying on the :money resource. After complete it would release those locks.
This means other trades with any of the involved entities could still happen as longs as they didn’t request a lock on the same resource/s for the same “starbases”.
Both options would be usable in a distributed setting as well. Perhaps they’re not very orthodox solutions, but I don’t see anything wrong with either.






















