Design a service that turns long URLs into short links, redirects on access, and reports click counts.
How to approach it
Every system has one signature hard problem the interviewer wants to watch you reason about. Identify it, lay out two or three approaches with their tradeoffs, and recommend one with a clear justification. Depth on the core problem beats breadth across components.
Short-code generation
Generate unique, short, hard-to-guess codes at ~115 writes/s with no collisions.
Approaches
| Approach | Tradeoff |
|---|---|
| Hash(long URL) + truncate | truncation collides; needs check-and-retry |
| Random base62 | must check existence; rare retries at this scale |
| Counter + base62 (ranges per host) | sequential/guessable but collision-free and fast |
Tip
Recommended — Pre-allocate counter ranges per host, encode base62 (collision-free, no read-before-write); add a salt if guessability matters.