How a URL shortener works
The classic system-design interview favorite — clients, API, cache, database and analytics — explained step by step with narration.
Browser
This is the system behind every short link you have ever clicked. It starts, as always, with the browser.
Load balancer
A load balancer is the front door. It spreads millions of requests across many identical servers so no single machine drowns.
Shorten API
The shorten API takes a long URL and mints a short code — usually six characters of letters and digits, which gives fifty-six billion combinations.
Redirect service
The redirect service does the opposite job: given a short code, find the long URL and answer with a redirect — in under ten milliseconds.
Redis cache
Redis keeps the most popular links in memory. Ninety percent of clicks hit a tiny fraction of links, so the cache absorbs almost everything.
Links database
The database is the source of truth. Every code and its destination lives here, replicated so nothing is ever lost.
Click events queue
Every click also drops an event onto a queue. The redirect never waits for analytics — that is the secret to staying fast.
Analytics warehouse
A worker drains the queue into the warehouse, where dashboards count clicks by country, device and hour. And that is the whole system.
Watch it explain itself
Every step above is narrated aloud. Play it, or open it in the editor and make it yours — no account needed.