The only way to prevent over-ordering is to lock all stocks at the moment they are added to cart. This is analogous to the real world when in a supermarket where the groceries are “deducted” from the shelves when they are “added” to the real shopping cart.
However, when customers in the supermarket decides not to check out and buy, they do not put the groceries back to the shelves. This is also true online and it becomes a problem because the stock count cannot be added back to cart in a timely fashion and subsequent buyers will have difficulty selecting the items they want.
In the online world, this implementation is only compulsory for time-sensitive products such as ticket bookings and the current way to overcome the problem is to set a time-out value where the items added to cart will be replenished back to the shelf stock count.