Hey everyone, we are running into an issue that I feel is extremely common - race conditions.
So the situation is simple:
- There is a product.
- Two (or three) try to buy the same product at nearly the same time.
- All three of them get the product in their shopping cart.
- There was only 1 of the product. Who gets it?
Essentially we have tried to reduce the “stock” of the item when an item is purchased, but what ends up happening is that the stock of the item does not change fast enough.
We have tried scheduling API workflows at random intervals in the future, but this is at best a temporary fix (and slows down the app a lot), and it doesn’t even work all the time.
In general programming I know that we would use a lock condition, but is there a way to “lock” the resource when it is being edited that isn’t also susceptible to the same issue?
This is happening on an auction site: when an item is dropped, all users see it at nearly the same time, and a lot of people are racing to claim it. Definitely not a fringe case, and this happens all the time.