When same function called at the same time twice, on of them doesn't update field

When same function called at the same time twice, on of them doesn't update field

Let's say whenever a record is created, your workflow reduces the "Quantity in Stock" field for one product. Your WF is associated with a function, which takes the Qty in Stock number, reduces it by one, and then updates it again. Simple. 

What happens when you call this function twice at the exact same time? Let's say your initial Qty in Stock number is 100. The first function (first by milliseconds), check the field, gets 100, reduces it to 99, and updates the field. No problem. The second function, though, checks the field, gets 100, reduces it to 99, and, yeah, updates the field again.

You should've had 98 as your end quantity, but instead, you have 99.  When this happens in greater numbers, your stock numbers will have an even greater discrepancy, and you will have a hard time understanding the problem because you did everything right and the process you are applying to records is extremely simple. And the problem will get bigger if you also have another workflow that's being triggered by the change in this specific field. 

About this specific problem I talked with Zoho Support, but they tried to make me believe that there is no problem. Well, from their perspective, all the functions are working, doing what they should be doing. Every line of code is doing what it should be doing, so there is no problem in the system. 

But there is a problem. Also, this problem only happens when you create two or more records at the same time, so there is no way for me or them to reproduce. The function works as intended when you make it work with one record. So how are we going to solve this problem that seems non-existent from the backend?

  1. One possible solution would be delaying each function randomly, so they happen at different times, thus reducing the possibility of the functions working at the same time. Deluge has a random number function but doesn't have a wait or delay function. It also doesn't have loops so except for going way too brute and writing a long delay function, this road doesn't give an elegant solution. Also, the delay doesn't totally guarantee that functions are going to happen at different times. 
  2. Another possible solution would be requesting the field just before updating it, and if it is the same value as the one you are about to update, then further reduce it. I implemented this. While it greatly reduces the number of issues, when the number of new records increases, you still get this issue occasionally. This solution also means more API calls. 
  3. Yet another possible solution would be using the workflow with scheduled actions, instead of instant action. This way, if Zoho had some queue, it could've put all the functions there and triggered them one by one. I also implemented this with a minimal time delay of 10 minutes. It turns out, that when scheduled actions are set up, Zoho bundles them together. This way more functions work together, so this solution actually increased our issues. 
  4. An easier solution would be if Zoho allowed you to set the delay time between functions. Unfortunately, there is no such setting. 
  5. Another solution would be comparing the newly created record numbers and product quantity decreases. Whenever there is a discrepancy, equalizing them with a new function. This requires us to write a complete new function, just for this checking procedure, and with growing products and branches, it will become harder to maintain, and cost us time and money.
I am talking with Zoho Support about this issue since the beginning of August and kinda lost my hope with them (about this issue, otherwise I am grateful to them for all their help). I don't know if this is a common issue, but it is bugging us for a longer time, and it was really hard to pinpoint. 

If there is any other way of fixing this problem, please write it down.