Back to TutorialsSystem Design · Chapter 12

Case Study: Designing a URL Shortener

A classic system design question that exercises nearly every concept from this course in one design. Here's how to structure the answer.

1. Clarify Requirements

Functional: shorten a long URL, redirect a short URL to the original. Non-functional: extremely read-heavy (many more redirects than creations), low redirect latency, and URLs shouldn't be easily guessable in sequence.

2. High-Level Design

A write path that generates a short code and stores the mapping, and a read path that looks up the code and redirects — these have very different scaling needs, which is worth calling out explicitly.

3. Generating Short Codes

Base62-encoding an auto-incrementing ID is simple and collision-free but reveals creation order and creates a write bottleneck on a single counter. Hashing the long URL is more distributable but needs collision handling. Discuss both, and pick one with a stated reason.

A hybrid worth mentioning: pre-generate a large pool of unique short codes offline and hand them out to write servers in batches, avoiding both a single global counter bottleneck and the collision-handling overhead of hashing. It's a good example of how combining two "textbook" approaches often produces a more practical answer than either alone.

4. Apply What You've Learned

Cache hot short-code lookups (Chapter 4), shard the mapping table by short code (Chapter 6), and put a CDN or edge cache in front of the redirect endpoint given how read-heavy it is (Chapter 7). This is exactly how these building blocks combine in a real interview answer.

5. Address the Non-Obvious Requirement

Non-guessable URLs matter more than candidates think — sequential IDs let anyone enumerate every link ever created. Randomizing the encoding or adding a non-sequential component addresses this without complicating the read path.

6. Wrap Up With Trade-offs, Not Certainty

Close by naming what you'd reconsider at 10x the scale — for example, whether a single relational mapping table still holds up, or whether you'd move to a distributed key-value store. Interviewers consistently rate candidates higher when they show awareness of their design's limits rather than presenting it as a finished, perfect system.

Extensions Interviewers Often Ask About

Be ready for at least one follow-up: link expiration and cleanup, per-link click analytics, or custom user-chosen short codes. Each pulls in a concept from earlier chapters — analytics naturally leads to a message queue writing to an aggregate store rather than incrementing a counter synchronously on every redirect, which keeps the hot read path fast.

Ready to put this into practice?

Upload your resume and get matched with a verified referrer today.

Get Started