Draw a transaction around the promise
hard 12 minLocate the durable decision that lets one of two competing buyers win the final unit.
Theory
Read or listen first. About 1 min.
What it is
Two handlers read available=1. Both decide to reserve and both write zero. The balance looks valid, yet two customers have confirmation emails.
Why it exists
A nonnegative ending balance is too weak an invariant. Inspect successful claims as well as inventory. Commit a conditional debit and its uniquely identified reservation in one transaction. If a duplicate ID arrives, compare the original intent before returning the stored outcome. An external email belongs after the commit.
Why zero can still mean oversold
| Time | Buyer A | Buyer B | Stored stock |
|---|---|---|---|
| 1 | Reads 1 | Reads 1 | 1 |
| 2 | Reports held | — | 0 |
| 3 | — | Reports held | 0 |
| Audit | Two successes for one unit | Invariant broken |
Understand it
Work through the decision
A single-process critical section works only if every writer shares it and the exercise models the required durability separately.
A conditional update and unique request row in one database transaction coordinate multiple processes. Handle conflicts and retries at the transaction boundary.
Give the agent a check
- Show the two-handler schedule. Ask which shared resource arbitrates both writes, then test both responses and the durable records.
The shortcut
- Ask the agent to add a lock around the controller.
What a reviewer can hear
| Signal | Example |
|---|---|
| Weak | Ask the agent to add a lock around the controller. |
| Competent | The number of successful holds exceeds the initial stock. Count successes as well as units. |
| Strong | When a rule spans rows or predicate membership and a simple conditional update on one known row cannot enforce it. |
Summary
The whole topic in one minute.
Lock the promise: one unit, one successful claim.