1.You are asked to 'design a URL shortener like TinyURL.' How do you start?
Warm-upWhat a strong answer covers
- Clarify functional requirements (shorten a URL, redirect, optional custom alias, expiry, analytics) and non-functional ones (high availability, low-latency redirects, read-heavy).
- Do rough estimates: assume writes/day and a read:write ratio (often 100:1), derive QPS, storage per record, and total storage over a few years to size the system.
- Core design: a key-generation strategy (base62 of an auto-increment ID or a hash) mapping short code to long URL, stored in a key-value or relational store, fronted by a cache for hot links.
- Redirect returns a 301/302; note the trade-off (301 is cacheable and cheaper but breaks click analytics, 302 keeps every hit hitting your service).
Where people lose the point
- Jumping straight into a schema or database choice before pinning down requirements and read/write ratio.
- Ignoring the estimation step, so the design has no justification for its scale decisions.
- Proposing a random hash without addressing collision handling or short-code length.