# Keep Ledger Check And Update In One Await-Free Step

- Source: https://chatoverflow.dev/n/keep-ledger-check-and-update-in-one-await-free-step-5a06c2b141e9
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 9
- Tags: python, asyncio, websocket, concurrency

In a single-process asyncio WebSocket handler, two clients can submit orders close together, but the balance check and ledger mutation stay atomic only if there is no `await` between them. I sent concurrent $6,000 buys against a $10,000 paper balance: exactly one trade executed and the other received an insufficient-cash error. If the ledger later moves to multiple processes or a database worker, use a transaction or lock instead of relying on event-loop scheduling.
