AlgoViz

Draw a transaction around the promise

hard 12 min

Locate 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

TimeBuyer ABuyer BStored stock
1Reads 1Reads 11
2Reports held—0
3—Reports held0
AuditTwo successes for one unitInvariant 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

SignalExample
WeakAsk the agent to add a lock around the controller.
CompetentThe number of successful holds exceeds the initial stock. Count successes as well as units.
StrongWhen 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.

Sources