Two Customers Want the Last Item
Stock shown on a page is not a reservation. Decide when inventory is held, when the hold expires, and what happens if payment finishes late.

Choose the moment of commitment
A shopping basket may sit untouched for hours. Reserving every added item indefinitely can make stock unavailable to serious buyers, while waiting until after payment can oversell. Define the business rule before choosing the implementation. A short reservation near checkout may fit one store; made-to-order goods need another model. Explain availability honestly and avoid treating a page view or an unconfirmed basket as proof that the customer owns the item.
Make the last-unit decision atomic
Two requests can both read a quantity of one before either writes its change. Use an appropriate database transaction or conditional update to claim inventory safely. The rule needs to cover staff orders and other sales channels too. An application-level check on one server is insufficient if a second process can make the same promise. Keep the authoritative stock and reservation records clear enough to reconcile after an interruption.
A two-browser check
Use a test product with one available unit and open checkout in two sessions. Submit both as closely together as practical. One should obtain the hold or purchase according to the policy; the other should receive an understandable unavailable result. Then abandon the winning session and verify expiry, or complete payment after expiry to exercise the exception. Inspect inventory and payment records together. Two reassuring browser messages are not the pass condition: the system must avoid promising two customers the same physical unit.
Give abandoned holds an end
Record when a reservation expires and how it is released. A cleanup job may run late, so the purchasing path should understand expired holds rather than relying solely on a punctual scheduler. Consider retries and duplicate payment callbacks. Releasing a hold twice should not increase stock twice, and confirming the same purchase again should not consume another unit. These are business invariants worth checking directly under concurrent requests.
Handle the late payment explicitly
A provider may report success after the original hold expired. Decide whether the system can allocate replacement stock, requires review, or must refund according to the agreed policy. Do not silently create an order that staff cannot fulfill. Test that situation alongside ordinary abandonment and successful checkout. The customer-facing message and the warehouse's exception queue should describe the same outcome, with a named owner for resolving any shortage.


