Let’s talk
All levels

Level 4 of 5 / you are the scheduler

The idempotency race

A client times out and retries the same payment with the same idempotency key. The handler looks the key up first, so a retry should be harmless.

Your goal: make one of these false

  • One order is charged oncenot checked yet
Originalapi-1
  1. const seen = await db.get("idem:ord_42");
  2. if (seen) return "REPLAYED";
  3. await payments.charge(₹499);
  4. await db.set("idem:ord_42", "done");
  5. return "PAID";
no local variables yet
Retryapi-2
  1. const seen = await db.get("idem:ord_42");
  2. if (seen) return "REPLAYED";
  3. await payments.charge(₹499);
  4. await db.set("idem:ord_42", "done");
  5. return "PAID";
no local variables yet

Database

idem_key
null
charges
[ ]

What happened

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