πŸŽ‰ Launch Sale: Get 30% off annual plans with code LAUNCH30

← Back to Blog
Web Servicesβ€’Beginnerβ€’56 min read

Design a URL Shortener

Asked at:GoogleMetaAmazonMicrosoftUberTwitter
Tech:Horizontal scalingShardingReplicationConsistencyAvailabilityCaching

A URL shortener looks trivial. Accept a long URL, return a short one, redirect anyone who clicks it. You could build a working prototype in an afternoon with a hash map and a web server.

But the moment you ask "what happens when 500,000 people click that link in the same second?" β€” the simplicity evaporates. Suddenly you are dealing with hot-key database pressure, cache stampedes, abuse vectors that can get your entire domain blacklisted, and an analytics firehose producing 600 GB of click data every day.

This post walks through designing a production URL shortener from first principles. Every decision β€” from the database to the cache layer to the analytics pipeline β€” will be driven by numbers, not instinct. We will start with a minimal working system and progressively harden it, exactly the way you would in a real engineering design review or a system design interview.

If you are reading this for the first time, think of it as a story. Each section builds on the last. The requirements tell us what to build. The capacity math tells us how hard it will be. The entities and APIs give us the vocabulary. The high-level design assembles the pieces. And the deep dives stress-test the weak points. Skip a chapter, and the next one will feel like you walked into a movie halfway through.

Let us begin.

1. Requirements β€” What Exactly Are We Building?

Before we draw a single box on an architecture diagram, we need to agree on what the system must do β€” and equally important, what it must not do. Scope creep is where system designs go to die.

Functional Requirements

Our URL shortener needs to do three things well:

  1. Create short URLs. A user submits a long URL and receives a compact, shareable short link in return.
  2. Redirect. When someone clicks that short link, the system resolves it to the original URL and sends them there β€” fast.
  3. Basic click analytics. The link creator can see how many times their link has been clicked.

That is it. Three user journeys. Everything in our design exists to serve one of these three.

Non-Functional Requirements

The functional requirements tell us what to build. The non-functional requirements tell us how well it must work:

  1. Redirect latency: p95 under 50 ms. The redirect path is the product. If clicking a short link feels slow, nobody will use the service. Fifty milliseconds at the 95th percentile means even under load, the vast majority of clicks resolve almost instantly.
  2. High availability on the redirect path. A link that does not resolve is worse than no link at all. The redirect path must stay healthy even when other parts of the system β€” analytics, admin dashboards β€” are degraded.
  3. Durable link mappings. Once a short link is created, the mapping must not be lost. A broken link that worked yesterday destroys user trust permanently.
  4. Collision-safe code generation. Two different long URLs must never produce the same short code. This sounds obvious, but at scale, it becomes a real engineering challenge.
  5. Abuse resistance. Short URL domains are high-value targets for phishing campaigns. Without controls, an attacker can generate thousands of malicious links in minutes.

Scope Control

To keep this design focused, we are explicitly drawing a boundary:

In scope: shorten, redirect, basic click count.

Out of scope: billing, advanced campaign analytics, A/B test bucketing, team management.

We can always add these later. But if we try to design for them now, we will over-engineer the core and under-deliver on what matters.

Now that we know what we are building and how well it needs to work, the next question is: how much load are we actually talking about? Without numbers, every architecture decision is just an opinion.

Login to continue reading

You reached the preview limit. Sign in to unlock the remaining sections.

Continue Learning

πŸŽ‰ Launch Sale!

30% off annual plans with code LAUNCH30

View Pricing