|
|
|
|
|
by ben509
2023 days ago
|
|
You don't need to hold the transaction open the entire time, you just need the inventory count to be correct. You track the inventory and reservations. Taking a reservation checks that inventory is available. With row-level locking, only that inventory item is locked. If that fails, it can search for timed out reservations, update the inventory and try again. If it succeeds, it decrements the inventory then adds a reservation. At that point, the transaction can close, and in the common case, you only held locks long enough to update a row in inventory and add a row to reservations. |
|