31. Design a URL Shortener
1
The interview prompt2
31.1 What do you ask first?3
31.2 How big is this, really?4
31.3 What are the doors?5
31.4 What do we store?6
31.5 What does the whole system look like?7
31.6 How do you generate the short code?8
31.7 301 or 302?9
31.8 How do you keep redirects fast at 12,000 a second?10
31.9 How do you count clicks without slowing redirects?11
31.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab31. Design a URL Shortener
The interview prompt
3 min read+10 XP
This chapter is a full interview round, played out step by step. The interviewer's lines are in quotes. At each step you'll see what a strong candidate says, the pushback the interviewer throws, and how to answer it. At the end, grade yourself with the rubric.
How to use this chapter
- Read only the prompt below. Then stop.
- Set a 45-minute timer and do the whole round yourself, on paper or a whiteboard, out loud. Use the framework from Chapter 1: READ, then Draw, Dive, Defend.
- Then read the walkthrough and compare. Score yourself with the rubric at the end.
Doing it first is the whole point. Reading a good answer feels like understanding. Producing one under a timer is what the interview tests.
The prompt
"Design a URL shortener, like bit.ly. Users give it a long URL and get a short one back. Anyone who opens the short URL is sent to the long one."
Stop here. Start your timer.