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.