The balance race condition
A wallet service adds a 'transfer' endpoint that reads the balance, checks it and writes the new value.
const wallet = await db.wallet.findUnique({ where: { id } });
if (wallet.balance < amount) throw new InsufficientFunds();
await db.wallet.update({
where: { id },
data: { balance: wallet.balance - amount },
});Two concurrent transfers can both read the same balance and both succeed, letting a user spend money twice. Use an atomic conditional update (balance: { decrement: amount } where balance >= amount) inside a transaction.
Result: A double-spend vulnerability is fixed before an attacker finds it with parallel requests.