Pessimistic locking under contention 00:00:01 Two agents and one concert seat Two ticket agents see the same free seat, P seven, shortly before a concert. The public chart can help them find it, but which agent will be allowed to promise it to a customer? Agent A grabs the row lock immediately to prevent others from changing the seat, even before checking if it’s still available. Agent B arrives at the same seat record and finds A already holding the lock, so it must wait until the lock is released. The lock belongs to a short database transaction. A green seat on a cached map remains only a hint for browsing; the identity of a seller and the current state of the seat must be checked at the authoritative record. 00:00:38 B must inspect the new state A inspects the current row while holding the appropriate lock, marks the seat sold and commits. The durable new state names the winning booking. B wakes up after the lock is released and rechecks the seat state under isolation rules. B cannot sell the seat because its earlier view of it being free is now outdated and invalid. Depending on the database and isolation level, a waiter may see the latest row or receive a serialization conflict and have to restart. Either route must lead back through the availability test before a sale is accepted. 00:01:10 What if A gives up? If A aborts the transaction, the lock is released immediately without any sale being recorded. B can now proceed, claim the seat, and commit it as sold without conflict. Contrast that with a commit—once A commits, B can no longer claim the seat, even if it was free earlier. Compare the two endings. A transaction that rolled back made no durable sale; one that committed left a durable owner. Receiving the lock after a wait does not tell B which ending occurred. 00:01:40 A transaction is a bad waiting room Holding the row lock while waiting for a remote payment could take over 60 seconds, tying up the system. Alternatively, claim a durable temporary hold in a short transaction, then release the database lock. Other agents can inspect the busy seat without holding an open transaction throughout payment. When a payment arrives, confirm only if the expected hold still owns the seat and is valid under the agreed policy. A late payment for an expired hold needs reconciliation. Give a durable hold its own identity, owner and expiration. A late provider result must be reconciled against that exact intent, so it cannot confirm a seat whose original hold has expired and been assigned elsewhere. 00:02:20 Choose contention you can afford A version check can be attractive when conflicting edits are uncommon. Optimistic and pessimistic approaches have different retry and waiting costs; neither is uniformly cheaper. A short row lock can give contenders a definite order for this shared seat. Long transactions can instead produce a line of waiters, so record the actual wait times. Track wait times and timeouts to ensure only one agent succeeds, preserving the one-winner invariant. Measure how long transactions hold the lock as well as how long others wait. Preserving one valid winner and giving a prompt, honest refusal to everyone else are both observable parts of this booking contract.