All levels
Level 2 of 5 / you are the scheduler
The lost update
A wallet holds ₹100. Two checkout tabs each try to pay ₹80, landing on different servers. The handler reads the balance, checks it, then writes the new balance.
Your goal: make one of these false
- The balance matches what was paidnot checked yet
- The wallet never goes below zeronot checked yet
Tab 1api-1
- const bal = await db.get("balance");
- if (bal < 80) return "INSUFFICIENT";
- await db.set("balance", bal - 80);
- await db.insert("ledger", -80);
- return "PAID";
no local variables yet
Tab 2api-2
- const bal = await db.get("balance");
- if (bal < 80) return "INSUFFICIENT";
- await db.set("balance", bal - 80);
- await db.insert("ledger", -80);
- return "PAID";
no local variables yet
Database
- balance
- 100
- ledger
- [ ]
What happened
- Step a request to begin.
0 steps · 0 switches · par 2