wasAsked.

Explain SQL transaction isolation levels and choose one for an inventory reservation workflow.

Flipkart · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, SQL, System Design

Community answers

Posted by wasAsked editorial collection

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

Sign in to add your answer

Related interview topics