The "quantity in stock" default is set at 9999. This quantity means that you have unlimited supply of the product, and no quantity information will be displayed to the user for the product. eg for wrapping paper, gift cards etc.
If you have limited stock, there comes a time, when a customer can only buy as much as you have.
If you have back order quantity enabled, then customers can buy more than you have, but will received a warning to expect a delay on fufilment.
The exact timing of when stock is reduced, is when a customer submits their order. This is after adding the item to the cart, and after adding their address, but before paying for the item.
If a customer does not pay for their item, the order remains unpaid, and stock remains locked. If you want to replenish stock, you can cancel an order. Some payment methods allow you to automatically cancel an order, depending on the method of payment. For example, you may wish to auto cancel credit card orders if unpaid within 1 hour. However, for online banking orders, you may allow several days for paymen to be received over a weekend.
Sometimes you only have 1 last item on the shelf, and you are eager to sell it. Our logic determines that the last item is available until such time as somone checks out, even if unpaid.
Only at the checkout time, is the stock locked. This can create an undesireable outcome, where multiple people attempt to buy the same item, and both attempt checkout. The fastest one to checkout wins. To counter act this issue, we have recently added additional logic, so that the first person to add the last available item(s) to their cart, gets 5 minutes headstart to checkout. In most cases, this means they can checkout without fear of losing the item in their cart. If they take longer than 5 minutes, then another user gets the change to add to cart, and proceed to checkout. The item is not deleted from the first customers cart. it remains after 5 minutes a battle to the checkout.
The reason we do not delete the items from the first persons cart, is we believe they both have reasonable right to checkout. We also have the situation where customers are creating wish lists, or saved carts, and it's possible stock will be replenished later. We also wish to view a history of what items a customer was interested in. The new logic helps give certainty to a customer, so long as they hurry and checkout. The new approach also encourages any sale to complete, as the merchant really does want someone to buy the item, and not have a situation where no one can, just because the first cart went cold.