Designing a URL Shortener: The First System Every Engineer Gets Wrong

The interviewer says: "Design a URL shortener." It sounds trivial — store a long URL, hand back a short code, redirect when someone visits it. Most engineers reach for the marker and start drawing boxes: a server, a database, a load balancer. Twenty minutes later the interviewer asks what happens at a billion redirects a day, and the boxes stop making sense.

A URL shortener is the first system every engineer gets wrong because it looks like a CRUD app and behaves like a distributed system. The mistake is never the boxes themselves. It is drawing boxes at all before answering four questions — what must the system do, at what scale, under which failures, and how will it change. Those questions are the actual subject. The shortener is just the cleanest place to watch an engineer either ask them or skip them.


The Problem Hides in Two Decisions

Strip away the plumbing and a shortener comes down to two decisions, and almost everyone gets this system wrong by never isolating them.

The first is how you generate the short code. Hash the URL and distinct URLs collide in a short code space — and a collision means one link silently redirects to another's destination. Generate a random code and check for it, and every write becomes a read-first that degrades as the keyspace fills. Use a monotonic counter and you never collide — but you have just created a single integer that every URL creation on earth contends on. Each option trades one hard property for another; the skill is seeing that the "obvious" answer relocates the difficulty rather than removing it.

The second decision is the read path. Links are read far more than they are written — the redirect, not the creation, is where the traffic actually lives — and a redirect that touches disk on every request will not hold its latency budget at scale. The moment you accept that the write path and the read path are two different systems with two different bottlenecks, the design starts to make sense. Until then, no arrangement of boxes will.


The Tradeoff: AT5 — Centralisation vs Distribution

The code-generation decision is, underneath, an AT5 choice. A single authoritative counter is the simplest thing that guarantees uniqueness — one source of truth, no coordination logic, provably no collisions. It is also a bottleneck and a single point of failure: every write in the system funnels through one incrementing integer, and when it stalls, creation stops everywhere. Pure centralisation buys correctness and pays in throughput.

Pure distribution — every node inventing its own codes independently — buys throughput and pays in the coordination you now need to keep two nodes from minting the same code. The interesting designs live between the poles: they keep a central authority for the thing that genuinely needs one and push the high-frequency work outward so the authority is touched rarely rather than constantly. Naming which property needs centralising, and which does not, is the whole move — and it is a choice about this system's scale and failure tolerance, not a universally right answer. The click counter, for instance, does not need the same guarantees the redirect does, and treating them identically is how engineers over-build one half and under-build the other.


Where It Fails: FM6 — Hotspotting

The failure waiting inside the naive design is FM6. Route every creation through one counter, or every redirect through one unreplicated store, and you have built a system whose throughput is capped by a single component's capacity — a hotspot that the back-of-envelope numbers expose long before production does. The tell is that the aggregate load looks survivable while one node in the middle of it is doing all the work, so the system falls over at a fraction of the capacity its hardware suggests.

The companion failure is FM1 — Single Point of Failure, and it hides in the same place. The component that guarantees uniqueness, or the store that every redirect depends on, takes the whole product down when it dies, because a shortener that cannot resolve codes has broken every link ever created with it. The mitigations exist — distribute the generation, replicate and cache the read path, decouple the counters that can tolerate lag — but which ones you reach for, in what order, follows directly from the scale estimate and the failure questions you answered first. Skip that estimate and you cannot tell a real bottleneck from an imagined one.


The Signal That Tells You This Applies

The signal is the one from the interview room: someone starts drawing architecture before stating requirements and running the numbers. The instant boxes appear ahead of a scale estimate, the design is being guessed rather than reasoned, and the guess will hold right up until the first question about the read path or a node failure. The disciplined alternative is boring and reliable — clarify what the system must do, estimate the load until the numbers force decisions, isolate the one or two choices that actually define the system, then design the read and write paths separately and name how each fails. The phases matter less than the order: understanding precedes drawing.

The counter-signal keeps this from becoming ceremony. Not every system hides its difficulty in two decisions — some really are CRUD apps, and running a full scale estimate on one is its own kind of over-engineering. The judgement is knowing which problem you have before you pick the method, and the shortener is the training ground precisely because it disguises the harder of the two as the easier. Learn to see the distributed system under the CRUD app here, and the pattern transfers — which raises the question every system-design problem eventually forces: once you can tell which decisions define a system, how do you work through the rest of the catalogue of components without re-deriving the method each time?


The full framework treatment — the five-phase method in detail, back-of-envelope scale estimation worked end to end, the three code-generation strategies and when each is correct, range-based ID allocation, the read-heavy cache path and its consistency tradeoffs, the failure-mode checklist, and the scaling path at 10× and 100× — is in Book 4: System Design Atlas, Chapter 1 (How to Approach System Design). Free chapter available at computingseries.com/books/book4.