Inventory deduction needs a transaction that locks or conditionally updates the specific tenant row, then verifies the affected row count. A single atomic update often avoids read-then-write races. Example: UPDATE Inventory SET Quantity = Quantity - @Amount WHERE RestaurantId=@RestaurantId AND OutletId=@OutletId AND ProductId=@ProductId AND Quantity >= @Amount; If zero rows were affected, report insufficient stock or missing scope. Keep transactions short and access rows in a consistent order to reduce deadlocks. Snapshot isolation improves many reads but does not replace write conflict handling. Add an idempotency key for retried orders and a stock-movement ledger so balances are auditable and repairable.
Backbencher Developer · · 0 likes