I’ve got a problem where I have an event publisher in c# serving up a global resource to a bunch of subscribers. The resource is a rival good, so it is possible that there won’t be enough of it for all the consumers.
The model to imagine is a shipment of ingredients arriving at a market. A number of chefs are waiting for each ingredient and must decide whether to buy some of each as each is served up. The chefs agree that everyone should have a shot at each ingredient, and they don’t want a race for each item, so they decide some kind of priority system should exist.
1) Is there a name for this kind of scenario?
2) What is a good way to implement this in a fair way, so each subscriber has an equal chance of getting the ingredient? Keep in mind that the decision on whether to ask for the resource is dependent on the subscriber.
3) Note that priority does not necessitate fixed priority. If you had a dice roll before each event, you could create an order each time. You could also precalculate this. Are there any drawbacks to such a solution?
Anyway, this isn’t a homework question. Just wondering if someone has seen this or is able to cast a common solution into a form that solves this.
Yes, it is called Round-robin (if I got it correctly)
The more complex the system, the easier you should make a solution, KISS works really well here. Implement a round-robin algorithm.
This problem has been around for many years in large scalable systems and networking (for example see this thread). People tried many things, but unless you really know what you doing, use a simple one-shot-each-in-a-round strategy.
Round robin is not perfect and definitely has its own drawbacks, but it is also the easiest solution.