How is optimistic concurrency used to prevent overselling stock?
Per-branch stock rows carry a RowVersion (a concurrency token). When the system decrements stock for an order, it issues a conditional update that only succeeds if the row hasn't changed since it was read; if two orders try to take the last unit at the same moment, one update wins and the other is detected as a conflict and retried or rejected, rather than both succeeding and driving stock…
Per-branch stock rows carry a RowVersion (a concurrency token). When the system decrements stock for an order, it issues a conditional update that only succeeds if the row hasn't changed since it was read; if two orders try to take the last unit at the same moment, one update wins and the other is detected as a conflict and retried or rejected, rather than both succeeding and driving stock negative. This *optimistic concurrency* approach means the database itself enforces correctness under simultaneous orders, so the platform doesn't oversell during traffic spikes or flash sales — a common failure mode in systems that read-then-write stock without a guard.