intermediateTransactions

Move Money Between Accounts

Decide what you would build from the brief alone. Everything below it is available, but the exercise stops working if you open it first.

The brief you were given

POST /transfers moves an amount from one account to another and writes two ledger entries. Neither side may end up wrong.

The trap — the wrong fix that looks right

Reading both balances, checking there are sufficient funds in application code, then writing both new values inside a transaction. The transaction makes the two writes atomic, which is what everyone checks, and it does nothing about the check: under Read Committed a concurrent transfer can move money between your read and your write, and both transfers pass a check that was true when it ran. The balance goes negative and the transaction commits happily, because nothing in the database was ever asked to enforce it.