Great question — answering as the UphillTech team:
Race conditions can occur at any stage of checkout, especially when there is a significant gap between supply and demand. In such cases, it’s better to use a First-Come, First-Served (FCFS) approach. A good example is a ticket-booking application: when supply is low and demand is high, they open the booking window but allow only a certain number of users to add the item to their cart. Once that limit is reached, additional users are placed in a queue until the previous users complete their checkout. Each user is given a fixed amount of time to finish checkout; if they don’t, the process stops for them and the next user in the queue gets a chance. Similarly, if an item is removed or updated...
Full answer by Nitin: https://stackoverflow.stackexchange.com/a/79835853 (CC BY-SA 4.0).
Need it done for your business? UphillTech.