← PracticeIntermediateShared State

Both Withdrawals Passed the Balance Check

Pull up the evidence one item at a time, commit to a diagnosis, and only then see the schedule that actually ran.

What was reported

A customer had £220 and made two £200 withdrawals from two devices, four milliseconds apart. Both were approved. £400 left the account. The account balance now reads £20 — not negative, which is why none of our balance alarms fired. Support only found it because the customer told us. We are single-threaded Node, so several people on the team think this is impossible.
1async function withdraw(accountId: string, amount: number) {
2 const balance = await db.getBalance(accountId) // ← check
3 if (balance < amount) throw new InsufficientFunds()
4 await db.setBalance(accountId, balance - amount) // ← act
5 await payments.send(accountId, amount)
6 return { ok: true, remaining: balance - amount }
7}

Evidence

Nothing here is labelled as relevant. Some of it is not.

What is actually happening?