Pessimistic locking under contention
medium 4 minAcquire ownership before using a value to make a dependent decision.
Video lesson · Chapter 1 of 5
Two agents and one concert seat
Two buyers want the same pair of seats
1:10Reel
Theory
Read or listen first. About 1 min.
What it is
A pessimistic reservation obtains control of the inventory rows before relying on their availability. The holder checks the complete bundle while competing buyers wait.
Reserve two seats as a pair
Why it exists
A queued buyer can discover that availability changed while it waited. Checking the locked records gives the buyer a sound basis for its next decision.
Words to know
- Lock acquisition order
- The sequence in which an operation requests locks when it needs several resources.
How it works
Step through the idea, or press Play.
Sort the seat IDs. Both buyers use the same resource order.
Understand it
Worked example
Pessimistic locking under contention in practice
A bundle requires two seats. Lock their inventory rows in increasing seat ID, verify both, and commit both claims. If either is unavailable, roll back without leaving half a bundle.
Related case
Who gets the last reservation?
A library releases a limited print edition at noon. Thousands see one copy available. A customer can reserve it for two minutes while checking out.
Compare item, owner, state and deadline.