Move balance between two accounts without losing any
Lock both rows in a fixed order, check inside the transaction, and write a ledger entry for each side. Skipping any of the three is how balances drift.
Integer balances, double-entry ledgers, atomic transfers and reconciliation.
5 entries
Lock both rows in a fixed order, check inside the transaction, and write a ledger entry for each side. Skipping any of the three is how balances drift.
Debit on request, not on approval. The state machine that makes double payouts and phantom balances impossible.
A caller-supplied key with a unique index turns every retry, refresh and double-click into a no-op. The single most valuable column in a payments schema.
Make the column unsigned, check inside the transaction, and let a clawback take a balance to zero rather than below it.
Compute the fee once, show the net before they confirm, and keep every threshold in the settings table so repricing is not a code change.