Quiz · URL shortener · lesson 10 of 10Quiz — URL shortenerQuestion 1 of 3123Why does a URL shortener take codes from a counter in base62 rather than random strings or URL hashes?[A]A counter is chosen because each new link increments one shared database row and reads it back, which is cheap at 40 writes a second. Random codes are avoided because they need 10 or more characters to stay unique.[B]A counter never repeats, so no write checks for a collision, and 7 base62 characters cover 3.5 × 10^12 values. Link-service instances take ranges of 1,000 values, and a fixed one-to-one shuffle before base62 keeps the codes out of sequence.[C]A hash of the long URL beats both: the same URL always gets the same code, the first 7 base62 characters of a hash never collide for different URLs, and no counter or shared state is needed, so any instance creates a link alone, without asking anyone.[D]A counter never repeats, so no write checks for a collision, and 7 base62 characters cover 3.5 × 10^12 values. Codes go out in plain order, which is safe enough: one code tells a visitor nothing about the links that other people made after it.← BackWhat interviewers askNext module →11 · Rate limiter