Betting Wallet Redesign
A wallet service where two bets placed at the same instant could both spend the same balance.
Balance protectedconcurrent bets cannot spend the same funds
Under load, concurrent bets on one account raced each other.
Moved the check and the debit inside a single transaction that takes a lock on the wallet row before reading it.
Writes to a single wallet now serialize, so a hot account is a throughput ceiling no number of instances can raise. That was the right trade: concurrency on one wallet is worth very little, and a double-spend is unrecoverable once the payout leaves.
- Bet Request
- Wallet Lock
- Check & Debit
- Commit
- Settlement
Betting Wallet Redesign — request path