# What are good algorithms for distributed purchasing?

I'm looking for some algorithms/patterns to solve a distributed systems problem.

Lets say I have created a trading platform buying stock (I haven't), and I have a distributed system of 50 nodes that are making these purchases for me. I also know that I have a budget of $50k, and it needs to be spent by the end of the day. I have some set of rules that determines whether or not to make the purchase, and if thats the case I purchase the stock. How do I ensure that I don't exceed my budget when these purchases occur quickly across every node? So node 49 doesn't get the memo that we are out of money, and spends$20K that I don't have.

Assume in this case, that a small amount overpurchase is acceptable, lets say 2% over time. We are also only concerned with the first discrete purchase beyond 50K, not a single purchase taking us from 49,999 to 50,100.

Are there good patterns that fit this sort of problem? Its seems similar to what Amazon or others might do for inventory management.

Thank you!

• here are some general pointers that might be useful: (0) there is a problem, called (distributed) consensus (1) the CAP theorem is a tradeoff between ensuring that data is synchronized and how fast the system responsds. (2) The C in CAP theorem can be achieved with algorithms, such as paxos and raft. there are a number of implementations available. I think there are a couple of other algorythms (3) the A part, also called eventual consistency. The classical example is Amazon Dynamo (there is a paper with this name). If this is what you need, you could probably look into gossip protocols too. Dec 22, 2021 at 21:06
• i don't know which one of those is good for trading. Dec 22, 2021 at 21:07