Atomic compare-and-set and reservation holds 00:00:01 Two promises about one library book Ada spots the last library book just as the clock hits noon—only one copy remains on the shelf, and she needs it for her thesis deadline. Ada obtains hold twelve for two minutes by changing the available book to held in one conditional update. The system records Ada as the owner and sets hold twelve to expire in exactly 120 seconds from now. A temporary hold is a distinct state between available and checked out. It needs an owner, an identifier and an expiration rule so that losing an old timer cannot accidentally release somebody else’s current claim. 00:00:42 Check expected state and identity For an initial claim, require an available or authoritatively expired record. For a later confirmation, check that the recorded hold is the expected one, belongs to the caller and is still eligible. If another user tries the same action, the system rejects it because the book is already claimed under this hold. A distinct hold identifier distinguishes this reservation from a later claim on the same book. Validate the caller separately; possessing a guessed number is not proof of authorization. The winning write and the losing write can arrive at different web servers. Enforce their condition at the shared book record; the two front ends do not need to agree merely by comparing local clocks. 00:01:30 Twelve expires and Bo arrives Exactly 120 seconds pass—no action from Ada—and the system marks hold twelve as expired by the authoritative clock. Bo arrives right after and claims the book under a new hold, now numbered thirteen, with a fresh two-minute window. The system refuses to reuse hold twelve, ensuring no confusion between old and new claims. Choose an authoritative interpretation of expiry at the operation boundary. A delayed cleanup worker need not run at the exact deadline if a new valid claim can safely recognize and replace an expired hold. 00:02:10 A delayed cleanup attempts the wrong thing Ada’s delayed cleanup routine finally runs—123 seconds after the original claim—too late to act. The old cleanup matches only a book still held under identifier twelve whose deadline has passed. Requiring an expired rather than an active deadline is essential for cleanup. Bo’s different hold does not match Ada’s cleanup condition. Whether Bo still holds the book or has already checked it out, Ada’s obsolete timer changes zero rows. Check the hold identity even when the old cleanup is allowed to run. Its job is to expire hold twelve, not establish that the book is generally available. That distinction protects the replacement owner. 00:03:01 Return the right customer outcome A duplicate confirmation request uses the same operation identity, so the system recognizes it as a retry. The original caller sees that the hold has expired and the book is now under a new reservation, not a fresh claim. With expiry first in the example, Ada receives an expired outcome and Bo retains the book. With confirmation first, the durable record would already describe Ada’s completed checkout. Test both orderings. If Ada validly confirms before expiry, her checkout survives. If expiry wins and Bo takes over, the same old confirmation must fail without damaging Bo’s ownership.