Learning on Web Dev Open is free for all.

Interview Prep · System DesignDesign a URL shortener
← System Design

Design a URL shortener

Easy35 minFree, no account

The classic warm-up, with a uniqueness problem that is harder than it looks.


The question

Design a service that turns a long URL into a short one, and redirects anyone who visits the short one.

Assume it is popular: tens of millions of links created a month, read far more often than written.

Functional
  • A user can submit a long URL and get back a short one.
  • Visiting a short URL redirects to the original.
  • A user may optionally request a custom alias.
Non-functional
  • 100M new links/month, 100:1 read:write, so ~4k redirects/sec average, ~30k at peak.
  • Redirect p99 under 100ms anywhere in the world.
  • Links are effectively permanent; losing one is unacceptable.
  • Short codes must be unguessable enough that nobody can enumerate the corpus.
35:00Commit to an answer before you open the solution. Reading it first teaches you to recognise good answers, which is not the skill being tested.

With a model in the room · Ask it for the design and you will get a correct, fluent, generic answer with 301 redirects and an unnecessary shard. The exercise is to find both before you present it.

Stuck?

0 of 3 hints taken

The worked solution

written by a person · not a grade

Score yourself

0 of 4 marked
  • Ran the numbers and used them to choose code length and reject sharding25
  • Named a code-generation scheme and its specific failure (collision or enumeration)25
  • Designed the read path deliberately: cache, immutability, 302 over 30130
  • Handled click counting without blocking the redirect20

We run no AI here and nothing on this page grades you. The score is yours, and the useful number is the one you get on the same problem a month from now, cold.

kept in this browser only