Atomically CLAIM a transition: UPDATE table SET set WHERE where, returning true iff this call changed a row.
The where MUST include the FROM-state guard (e.g. and(eq(id, n), eq(status, "pending"))) so a re-delivery /
concurrent caller finds the row already transitioned and changes nothing → returns false. The single point that
makes a once-only side-effect (charge, refund, decrement, email) safe to run when, and only when, the claim wins.
Atomically CLAIM a transition:
UPDATE table SET set WHERE where, returning true iff this call changed a row. ThewhereMUST include the FROM-state guard (e.g.and(eq(id, n), eq(status, "pending"))) so a re-delivery / concurrent caller finds the row already transitioned and changes nothing → returns false. The single point that makes a once-only side-effect (charge, refund, decrement, email) safe to run when, and only when, the claim wins.