Let’s talk
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
  1. const bal = await db.get("balance");
  2. if (bal < 80) return "INSUFFICIENT";
  3. await db.set("balance", bal - 80);
  4. await db.insert("ledger", -80);
  5. return "PAID";
no local variables yet
Tab 2api-2
  1. const bal = await db.get("balance");
  2. if (bal < 80) return "INSUFFICIENT";
  3. await db.set("balance", bal - 80);
  4. await db.insert("ledger", -80);
  5. return "PAID";
no local variables yet

Database

balance
100
ledger
[ ]

What happened

  1. Step a request to begin.
0 steps · 0 switches · par 2