Inventory & Warehouse

How does stock decrement atomically to avoid overselling under concurrent orders?

Stock decrements use optimistic concurrency: per-branch stock rows carry a version token, and a decrement only succeeds if the row hasn't changed since it was read. If two orders try to take the last unit simultaneously, one succeeds and the other is detected as a conflict and retried or rejected — so stock can't be driven negative and the item isn't oversold. The database enforces this…

Stock decrements use optimistic concurrency: per-branch stock rows carry a version token, and a decrement only succeeds if the row hasn't changed since it was read. If two orders try to take the last unit simultaneously, one succeeds and the other is detected as a conflict and retried or rejected — so stock can't be driven negative and the item isn't oversold. The database enforces this correctness, which is exactly what's needed during flash sales or traffic spikes where naive read-then-write logic would oversell.