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
- const seen = await db.get("idem:ord_42");
- if (seen) return "REPLAYED";
- await payments.charge(₹499);
- await db.set("idem:ord_42", "done");
- return "PAID";
no local variables yet
Retryapi-2
- const seen = await db.get("idem:ord_42");
- if (seen) return "REPLAYED";
- await payments.charge(₹499);
- await db.set("idem:ord_42", "done");
- return "PAID";
no local variables yet
Database
- idem_key
- null
- charges
- [ ]
What happened
- Step a request to begin.
0 steps · 0 switches · par 2