Dev Skills

Design a URL shortener (TinyURL)

Design a service that turns a long URL into a short one, and sends anyone who visits the short link to the original. Anyone can create links; links do not expire by default.

About this problem

“Design a URL shortener (TinyURL)” is a starter-level problem in the read-heavy / caching family. Few people write. Many read, and they read the same few things.

The key challenge: A person is standing in front of a blank browser tab waiting to be redirected. There is nowhere to hide latency on the read path.

Time budgets: Reads: none. Writes: seconds.

The worked solution for URL shortener goes through why those budgets shape the design, stage by stage.

Before you start

You will work this in five timed stages. Here is what each one asks you to think about. None of it is the answer; the answers unlock in the workspace below once you have written your own.

  1. Stage 1 · Requirements · 5 min
    • Which assumptions here actually change the design — and which are just settings?
    • Is there a question about who owns the links, or about whether custom names are allowed?
    • Say the read/write split as an assumption. It is the most load-bearing one.
  2. Stage 2 · Actors and lifecycle · 6 min
    • Who touches this besides the person creating and the person clicking?
    • What decisions does the platform make without being asked?
    • At each state: what if this never finishes? What if the thing on the other end is gone?
  3. Stage 3 · Numbers · 6 min
    • Pick a daily creation number and say you picked it.
    • Reads are a multiple of writes — choose the multiple and justify it.
    • Storage: how many bytes is one link row?
  4. Stage 4 · High-level design · 12 min
    • Start at the click and follow it to storage and back.
    • For each box, say the one number or requirement that put it there.
    • How is the short code generated? That is a design decision, not a detail.
  5. Stage 5 · Deep dive and tradeoffs · 14 min
    • The numbers said read latency and collisions. Go there.
    • What happens when the cache is empty or dies?
    • What is the abuse story? This service is a gift to spammers.
Prefer to read first? The worked solution, end to end →

Work it through

Five stages, gated. You write your answer for each stage before its model answer unlocks. That is the core of the method.

Loading your progress…

Done all five? The diagrams, numbers, trade-offs and follow-ups for this problem are on the worked solution page, to check your own design against.

Before you leave
Try this problem again in a week without reading anything. Comparing what you write then with what you wrote today shows you what stuck.
Stuck, or new to this?Read the full worked solutionAll five stages end to end, with the diagrams and the costs, written out the way you would say it. Best read after you have had a go.Read it →

How it is really built

Write your own answer first. Then read how teams who run this at scale describe it. Their constraints were real, and the write-ups often say what their choices cost.

  • Amazon Dynamo paper ↗The key-value store this problem usually ends at, and why it chose availability over consistency.