Let’s talk
URL Shortener track · step 3 of 8

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
  1. const n = await db.get("counter");
  2. await db.set("counter", n + 1);
  3. await db.insert("links", encode(n));
  4. return "SHORTENED";
no local variables yet
Bobapi-2
  1. const n = await db.get("counter");
  2. await db.set("counter", n + 1);
  3. await db.insert("links", encode(n));
  4. return "SHORTENED";
no local variables yet

Database

counter
1000
codes
[ ]

What happened

  1. Step a request to begin.
0 steps · 0 switches · par 2
Next in the trackThe vanity alias race