Q&A-1In a system design round you have an AI assistant that drafts components on request. For a URL shortener, it proposes a 6-character base62 code generated at random with a unique index. Is that acceptable, and what would you check before keeping it?
Answer
The first 90 seconds. I don't accept the proposal as written. I treat it as a claim to check, and I say so. The question I ask is whether 6 random base62 characters survive the stated load. I restate the one number the assistant was never given: 100 million new links a year, with a five-year horizon.
The arithmetic is short. 62^6 is about 5.7e10 codes. Over five years I need 5e8, so roughly 0.9% of the space is used at the end of the period. Random generation with a unique index has a collision probability per insert that rises with occupancy, so by the final year a fresh random code collides about 0.9% of the time. That is not a failure, because the unique index rejects the duplicate and the service retries. So the design is acceptable only with that retry path written into it, and the retry path has a cost: a write that needs a second round trip at the tail of the lifetime.
Claim from assistant Check I ran Result
6-char base62 code 62^6 = 5.7e10; 5e8 used at yr 5 ~0.9% occupied; retry path required
7-char base62 code 62^7 = 3.5e12; 5e8 used at yr 5 ~0.014% occupied; retries rare
The 7-character version costs one more byte per code and removes most of the retry traffic. I would keep 6 only if the URL length budget is tight and the interviewer agrees the retry is acceptable.
Alternatives. Random codes with a unique index are simple and need no coordination. A counter encoded in base62 has no collisions and produces dense, guessable codes, which may be a privacy issue if links are meant to be unguessable. I compare them on that main trade-off: collision handling against guessability. I would reject the counter if the product needs unguessable links, and reject random if writes must never retry.
Failure modes. (1) A write-path retry loop with no bound, which turns a 0.9% collision rate into unbounded latency if the random source is biased. I detect it with a metric on retries per insert. (2) Trusting the assistant's space figure without checking whether it assumed 62 or 36 symbols. (3) Keeping the code and dropping the question of guessability, which the interviewer will ask about next.
So the strong answer states the assumed load, runs the space calculation, names the retry or length trade-off, and says which parts of the generated design I would change.
Curated: · Written: · Reviewed: