Skip to content
Theory · URL shortener · lesson 1 of 10

Problem and requirements

What you'll learn

What you'll learn:

  • work out a URL shortener's requirements by asking the interviewer;
  • estimate load and data size on paper;
  • build the design step by step, from two request paths to click counting;
  • explain where a short code comes from and why a redirect answers 302.
A narrow lane makes the card aZ3kQ9 and files it; the wide x100 lane takes it from a shelf by the door and returns a 302 signpost

The URL shortener prompt goes like this. Design a service like bit.ly: a user pastes a long URL and gets a short link back, such as https://sho.rt/aZ3kQ9. When someone opens the short link, the service redirects them to the original URL. Before reading on, sketch how such a service could work.

Sketch

A user sends a long URL and gets a short link back. Anyone who opens the short link lands on the long URL. Add what this cannot work without, and connect the blocks.

A URL shortener is often the first prompt in a system design interview. Anyone who has ever clicked a short link understands the service, and inside it has everything interviewers check: load, a cache, storage, unique codes and failures.

The interview lasts 45 minutes. The interviewer knows the product requirements and the expected load but will not state them: ask before you design.

Try it yourself first

Build the design on the practice canvas: the AI interviewer answers your questions about the requirements and checks your solution. Then compare your design with the walkthrough in this chapter.

Open the prompt

Why ask first

Imagine being asked to build a bridge without being told whether it crosses a stream or a river. A footbridge of two planks and a bridge on piles are different projects. A shortener is the same: a service for 1,000 links a day and one for 100 million links a month are built differently.

The interviewer checks whether you notice this. The first five to seven minutes go to questions. Write down every answer: the whole design rests on these numbers.

Questions worth asking for this prompt:

  1. Who can create links: any visitor or only a signed-in user?
  2. Can a user pick their own short code?
  3. Do links live forever, or do they expire?
  4. Does the owner need click statistics, and how fresh?
  5. How many links are created a month, and how many times is each one opened?
  6. How long are links kept, and how long can a URL be?
  7. How fast must a redirect be, and how critical is it?

Functional requirements

These are what the service does. For this prompt the interviewer answers like this:

  • a user submits a long URL and gets a short link, and anyone who opens it is redirected to the long URL;
  • anyone can open links, but only a signed-in user can create them;
  • a user can pick a custom alias of 4–30 letters, digits and hyphens, if it is free;
  • a link may have an expiry date, and after it, or after deletion, the link answers "not found";
  • the owner sees how many times a day each of their links was opened, and these numbers may lag by an hour at most;
  • once created, a link cannot be pointed at another URL, only deleted.

Non-functional requirements

These are how well the service works:

  • a redirect takes under 50 ms at the 99th percentile: 99 redirects out of 100 fit within that time;
  • redirects are available 99.99% of the time, link creation 99.9%;
  • a new link starts working within seconds of being created;
  • other people's links must be hard to find by trying codes in sequence;
  • users live all over the world, and the code should be as short as possible, seven characters being acceptable.

Note the difference in availability. Redirects may be down for about 53 minutes a year, link creation for almost nine hours. Because of this difference, the redirect path and the link-creation path are built differently.

What stays out of scope

The interviewer will say equally plainly what not to design: the web UI, paid plans, how sign-in works and malware checks on URLs. Name these limits out loud: it shows you set them aside on purpose rather than forgot them.

Common mistake

Drawing boxes right away without asking a single question. The candidate puts down a database and a service, and ten minutes later it turns out click statistics are needed. Half the diagram has to be redrawn, and the interviewer notes that you did not find out the requirements. There is one fix: questions and numbers first, design second.

Key points

  • The prompt is short on purpose: finding out the requirements and the load is your job.
  • Functional requirements say what the service does, non-functional ones how fast and how reliably.
  • Redirects matter more than creation: they are available 99.99% of the time against 99.9% for creation, and answer in under 50 ms.