System Design - URL Shortener
A short URL service end to end: short-code generation, storage, caching, and redirects.
What is a URL shortener?
A service that turns a long URL into a short code and redirects visitors back to the original. bit.ly and t.co are familiar examples.
Where you will see it
Real systems that use this exact idea. Tap a card to open it.
Common traps
The mistakes interviewers watch for. Guess the fix, then reveal it.
FixHashes collide. Either retry-on-collision with DB uniqueness check, or use counter-based IDs encoded in base62 - deterministic uniqueness.
FixA synchronous DB increment doubles your write load on the hottest path. Fire an async event instead.
FixOnce a browser caches the 301, it never returns. If you need ongoing analytics, use 302 or accept the trade-off explicitly.
Interview prep
Questions you could be asked, with the depth an interviewer wants to hear.
A client posts a long URL to the API through a load balancer. The API asks an ID generator for a unique short code, stores the shortCode to longUrl mapping in a database, and caches hot lookups. Reads look up the code and return a 301 redirect.
write O(1) · read cached
Real worldbit.ly and t.co follow exactly this shape, with the cache absorbing almost all read traffic.
DeeperThe ID generator is the subtle piece: it mints collision-free codes without a central counter.