~20 minutes · Day 79 · system design
Tonight's interview design is a URL shortener: turn a long URL into something like /aB7x9Q, then redirect anyone who visits that code. It looks tiny, which is why interviewers like it. The product is simple enough to draw, but it exposes the real system-design habit: find the path that gets the most traffic, then protect it.
A tiny write path (issue an ID, base62-encode it) feeding an enormous read path — design for the reads: one lookup per redirect, cache the hot links.
The system-design script is always: requirements → estimate scale → API → data model → high-level boxes → deep-dive the bottleneck → failure modes. Apply it in that order; do not jump straight to boxes.
POST /links creates a code. GET /{code} returns an HTTP 302 redirect with the target in the Location header.code, long_url, created_at, expires_at, and optional owner_id. Make code unique.GET /{code}: one lookup, then redirect. Analytics, abuse checks, and counters must not sit in front of the redirect.POST /links
{ "long_url": "https://example.com/really/long/path" }
201 Created
{ "short_url": "https://sho.rt/aB7x9Q" }
GET /aB7x9Q
302 Found
Location: https://example.com/really/long/path
The write path can be boring: ask an ID generator for the next number, Base62-encode it, save the mapping, return the code. Boring is good. The read path is where the system earns its design.
The bottleneck is not making the short code. It is serving the same popular code again and again without melting the database. Three cache choices are worth saying out loud:
For a first interview pass, choose cache-aside with bounded LRU, then mention that a production system may upgrade the admission policy if traffic is extremely skewed.
| Figure | Why it matters | Source |
|---|---|---|
62^7 ≈ 3.5 trillion codes | Seven Base62 characters leave a very large code space. | Base62 alphabet |
| 1 request/sec ≈ 2.5 million/month | Fast mental conversion for back-of-the-envelope sizing. | System Design Primer |
| 10:1 reads to writes | Good starter assumption for URL-shortener traffic. | System Design Primer |
| Cache examples exceed 100k ops/sec | In-memory cache absorbs hot redirects before the database. | Redis benchmarks |
302 + Location header | The redirect response only needs the target URL. | MDN HTTP 302 |
1. Redirects are far more common than creates. What should you optimize first?
2. Which redirect-path design keeps the user-facing request shortest?
3. A celebrity shares one short link; millions click it. Which cache policy is the clean default?
4. Why use an ID generator before Base62?
Redraw the architecture diagram from memory on paper. Then explain the design out loud in 5 minutes as if an interviewer is listening: requirements, scale, API, data model, boxes, bottleneck, failures. No LeetCode tonight.
For the encode step in your Notion tracker, write the invariant in your own words. The sentence should mention both sides: tiny write path, enormous read path.
Read System Design Primer — Design Pastebin.com (or Bit.ly) after your redraw, as the “compare” step. Focus on where it adds cache, replicas, and scaling only after the basic design is clear.
Stuck or curious? Ask your teacher (the agent) — that's what it's for.