Infrastructure primitives
URL shortener - one write, a million reads
Why one tiny write and a hundred cacheable reads make two systems sharing a single table.
The first act plays here. Owned once with credits, never a subscription.
What this board gets wrong on purpose
The tension
Uniqueness is bought with a single global counter: every write in the world waits on one INCR, that counter is the only node here with no replica, and base62 of a counter makes every link on the service enumerable by walking the range. Read scale is bought with the opposite mistake - the CDN caches the 301, so after the first visitor a deleted or re-pointed link keeps redirecting until the TTL expires, and the clicks that never reach the service are never counted.
Practise this as an interview
Take URL shortener - one write, a million reads as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
The URL shortener is the most common opening question in a system design interview because the product fits in one sentence and the hard parts do not. It probes whether you start from requirements and numbers, whether you see that a 100:1 read-to-write ratio means two different systems sharing one table, and whether you can defend a key-generation scheme and an HTTP status code under questioning. In real life the same shape - tiny write, enormous cacheable read - is every link tracker, QR code service, feature-flag lookup and DNS-like resolver.
What you will learn
- How to turn 100M new links a month into ~40 writes/s, ~3,900 redirects/s on average and ~19,000/s at peak - and why bandwidth is not the constraint here.
- Why a 7 character base62 key (62^7 ≈ 3.5 trillion) outlasts ten years of 1.2 billion links a year with 99.7 percent of the space unused.
- Counter-based keys against random keys: collision-free and short versus no single point of failure and not enumerable - and the range-leasing middle ground.
- Why the read path sits behind two caches, and what a cached redirect costs: stale deletes and clicks that are never counted.
- 301 against 302: the status code decides your server load, your analytics accuracy and whether you can ever take a link down.
How to read this board
- Diagram first. WRITE PATH · CREATE A LINK across the top: author, client, the Shortener API hex, the key encoder and the red counter.
- Then DATA on the right: the link store, written once by the top half, and the hot key cache in front of it for the bottom half.
- Then READ PATH · FOLLOW A LINK across the bottom: visitor, CDN edge, the redirect service hex, and the 301 looping back. Then ANALYTICS · OFF THE PATH: click events, click store, link analytics. Press play for the eight step walkthrough.
- Then the pages in order: 1 · Requirements, 2 · Capacity estimation, 3 · Storage estimation, 4 · Availability, 5 · How it works, 6 · Deployment plan.
- Last, DATA MODEL under the pages: the links row and the click_daily rollup, as real tables that Generate SQL turns into DDL.
- The conversation to have is the red box and the CDN. Uniqueness is bought with one counter that has no replica and makes every link enumerable; read scale is bought with an edge-cached 301 that keeps deleted links alive and never counts the clicks it serves. Page 5 argues both trades; decide which you would change first.
1 · Requirements
Write the requirements before drawing anything: the two non-functional lines about read latency and key uniqueness decide nearly every box on the diagram.
Functional
- Create: given a long URL, return a short link https://sho.rt/{key}. The same long URL submitted twice may return two different keys unless the caller asks for dedup.
- Redirect: GET /{key} answers with an HTTP redirect to the long URL, or 404 if the key is unknown, deleted or expired.
- Optional custom alias (sho.rt/launch) and optional expiry date, both chosen at creation.
- The owner can delete or disable a link. Abuse reports can disable one centrally (malware, phishing).
- Per-link analytics: clicks by day, referrer and country - approximate is acceptable.
- Authenticated API with per-key rate limits for creation, since a shortener is a favourite tool for spam.
Non-functional
- Redirect latency: p99 under 50 ms at the origin, under 20 ms when served from the edge. A redirect is an extra hop before the page the visitor actually wanted.
- Redirect availability 99.99 percent (about 4 minutes a month). A dead redirect breaks every link ever printed on a poster or in an email.
- Create availability 99.9 percent. A failed create is retried by a person; a failed redirect is not.
- Uniqueness is absolute: two links may never share a key, and a key is never reused after deletion.
- Durability: a link that has been returned to its author must survive any single machine, zone or region loss.
- Reads may be eventually consistent by seconds; a newly created link must work on its first click (read-your-write for the author).
- Analytics are best-effort and eventually consistent; they must never slow a redirect.
Out of scope
- Link previews, QR rendering, branded domains per customer and A/B routing - each is a feature on top of the same lookup.
- Exact, billable click counts. If clicks are money (ad networks), the design changes: no edge caching and a durable click log.
- Content scanning of the destination page beyond a blocklist check at create time.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, an 8-step narrated walkthrough and a 2-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
- 2tables10 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan