URL Shortener track · step 3 of 8 Next in the trackThe vanity alias race
Level 5 of 5 / you are the scheduler
The ID collision
A URL shortener turns an auto-increment counter into a short code. Two requests shorten different URLs at the same instant. The handler reads the counter, bumps it, and encodes what it read.
Your goal: make one of these false
- Every short code is uniquenot checked yet
Aliceapi-1
- const n = await db.get("counter");
- await db.set("counter", n + 1);
- await db.insert("links", encode(n));
- return "SHORTENED";
no local variables yet
Bobapi-2
- const n = await db.get("counter");
- await db.set("counter", n + 1);
- await db.insert("links", encode(n));
- return "SHORTENED";
no local variables yet
Database
- counter
- 1000
- codes
- [ ]
What happened
- Step a request to begin.
0 steps · 0 switches · par 2