A shop can show the same available copy to many readers. The promise begins when a write changes a particular copy from available to held. Store the customer’s hold identity and its deadline together. The identity distinguishes successive holders even if the item leaves and later returns to the same visible state.
Ownership changes when a hold expires
Ada holds the last item until 10:05. A competing claim must wait or fail while Ada’s hold is active.
Why it exists
Keeping a database transaction open while somebody enters payment details would tie a lock and a connection to human response time. A short transaction can instead record a durable hold. Other requests inspect that state and finish quickly while the customer checks out.
View diagram · Claiming one copyMatching the active hold prevents cleanup from touching Bo’s purchase. Full size
Words to know
Hold identity
A unique claim on one item during one reservation period.
Conditional write
A mutation that succeeds only if the stored state still satisfies its predicate.
How it works
Step through the idea, or press Play.
Step 1 of 3
Make one durable claim. Conditionally change available to held, recording the hold ID and deadline. Affected rows tell the caller whether it won. A waiting room bounds traffic but cannot enforce ownership.
Choose how writers contend. A row lock lets the winner inspect and update several fields in one short transaction. A version predicate lets callers race, with losers rereading. Under heavy contention, repeated retries consume the same scarce capacity.
Resolve the expiry race. Confirmation must match the active hold ID and satisfy the deadline on the authoritative clock. Expiry must match that same hold. A delayed cleanup for buyer A must never release buyer B’s newer reservation.
Understand it
Start here
Two readers at the library desk
Ada wants the only copy of a new book. The desk gives her two minutes to collect it. Watch the ticket attached to the book when Bo arrives after her time runs out.
Two readers at the library desk
Compare item, owner, state and deadline.
Structure
Claiming one copy
Claiming one copy
Matching the active hold prevents cleanup from touching Bo’s purchase.
Two buyers, one copy
A acquires hold 12 at noon. At 12:03 B replaces the expired hold with hold 13. Now deliver A’s confirmation and its delayed cleanup in either order. Both must affect zero rows. B must still be able to confirm once.
The lifetime of one copy
flowchart TD
A["Available"] --> B["Held by Ada"] --> C["Expired"] --> D["Held by Bo"] --> E["Sold to Bo"]
The previous buyer returns
Time
Request
Result
12:00
Ada claims copy 8
Hold A expires at 12:02
12:03
Bo claims expired copy 8
Hold B replaces hold A
12:04
Ada confirms hold A
Owner check fails
12:05
Delayed cleanup for A runs
B’s hold remains intact
Where to spend the contention budget
For low contention, attempt a conditional update once and tell the loser the item is unavailable. For a bundle of items, acquiring rows in a stable order within one short transaction can simplify all-or-nothing allocation. During a popular sale, repeated losing writes can dominate database time. Limit admission before the database and monitor attempts per successful reservation.
Payment can outlive the hold
Suppose payment authorization succeeds just after the reservation expires. Treat fulfillment and payment as distinct states. Verify the hold before confirming the item and record a recoverable outcome if payment needs to be voided. Test the ordering where the payment result arrives twice and the cleanup process runs in between.
Match the hold
Compare item, owner, state and deadline.
Match only the item
An older timer can release a newer claim.
Summary
The whole topic in one minute.
A hold needs an identity, an authoritative deadline and guarded transitions. Cleanup improves availability; the confirmation path enforces ownership.