Design a link shortener

The question

Design a link shortener: someone pastes a long URL and gets a short one back, like sho.rt/aZ3k9Q. Anyone who opens the short link is sent to the long URL.

What this page is

A system design round has no single right answer. Interviewers listen to how you think, more than to the boxes you draw. This page walks through one strong answer, in the order a good candidate gives it.

At each step, stop for a minute and think about what you would say. Then open the step and compare. You will pick up the shape of a good answer, which works for most design questions, not just this one.

Four habits that carry over

  1. Ask before you draw. Requirements and scale first. State your assumptions out loud.
  2. Do the numbers. Rough estimates decide the design.
  3. Simple first, then scale. One server and one database that works, then what breaks and how you would fix it.
  4. Say the tradeoffs. Every choice gives something up. Name it.