Skip to content
All problems

Design a URL shortener at bit.ly scale

breadth · 45 min · senior/staff

Setting

You've joined the platform team at a link-management company. Marketing customers create branded short links and need click analytics; the redirect path is on the critical path of every campaign click on the internet.

The ask

Design the system that creates short links and serves redirects, including click analytics.

Constraints & scale

  • ~100M new links/month, ~10B redirects/month, heavy tail (a handful of links get 1M+ clicks/hour during launches)
  • p99 redirect latency < 50 ms globally
  • Links live for years; analytics must be near-real-time (< 1 min) for dashboards
  • Custom aliases must be globally unique; abuse/malware links must be killable within seconds

What a strong answer covers

Requirements → estimates → API/data model → high-level diagram → 1–2 deep dives → trade-offs. Likely probes: the redirect hot path, ID generation, and analytics ingestion.

A 45-minute plan

  1. 0-5 min · Requirements
  2. 5-10 min · Estimates/API
  3. 10-25 min · High-level
  4. 25-40 min · Deep dive
  5. 40-45 min · Wrap

What to cover, in order

  1. Requirements
  2. Estimates
  3. API/data model
  4. High-level diagram
  5. 1–2 deep dives
  6. Trade-offs

Where the follow-up questions go

Pick one of these for your deep dive before the interviewer picks for you.

  • The redirect hot path
  • ID generation
  • Analytics ingestion

Key trade-offs

Decisions a strong answer weighs, and what pushes each one either way.

  • Counter or hash for ids. A counter (range-allocated, then base62 encoded) never collides but leaks creation order and needs a coordinated allocator. A hash of the long URL is stateless but collides, so you need a check-and-retry on insert and a longer code to keep that rare. Guessable ids matter more if links can be private; at 100M links a month either works if you say how you handle the failure case.
  • Cache-first redirects or fresh reads. Serving from an edge or regional cache keeps p99 low and protects the database, but every cached copy can outlive a delete, an edit or an abuse takedown. The shorter the TTL, the more the origin is hit. Decide how fast a killed link must stop resolving and pick the mechanism (short TTL, purge, or a small kill list checked on every hit) to match.
  • 301 or 302. A permanent redirect is cacheable by browsers and cuts load, but later clicks never reach you, so analytics undercount and a takedown cannot reach those browsers. A temporary redirect costs a request per click and keeps you in control. Analytics and abuse control usually push toward 302.
  • Sync or async click logging. Writing the click before responding gives exact counts but puts a write on the latency-critical path. Emitting an event to a queue and aggregating later keeps the redirect fast and allows a small loss. The one-minute freshness target is what makes async clearly right here; the real question is how much loss you accept and how you dedupe.
  • Exact or approximate counts. Exact per-link counters under a viral spike create a hot row. Sharded counters or periodic roll-ups spread the write load at the cost of a few seconds of lag and slightly fuzzy totals. Billing-grade accuracy and a marketing dashboard want different answers.

Common mistakes

What goes wrong most often on this problem, and why it hurts.

  • Treating the redirect as a normal database read. At ten billion redirects a month with a heavy tail, a handful of links dominate traffic. Without caching in front, those few keys overload their shard while most of the cluster idles.
  • Hashing the long URL and ignoring collisions. Two different URLs can map to the same short code, and the same URL submitted by two customers should usually get two separate links. Without a defined collision path you serve someone else's destination.
  • Writing each click synchronously to the primary store. It adds latency to the path that must stay under 50 ms and turns a viral link into a write storm on one row.
  • Skipping custom-alias uniqueness. Checking whether an alias exists and then inserting it is a race. Two requests can both pass the check, so you need a unique constraint or a conditional write as the source of truth.
  • No plan for expiry, deletion and abuse. Links live for years, so stale and malicious links accumulate. If takedown is not designed into the cache layer, the claim that bad links die in seconds is unsupported.

Graded on

Requirements & scoping · Estimation · API & data model · High-level architecture · Deep dive · Scalability & performance · Reliability & consistency · Trade-offs · Operability · Communication & drive

Ready to run this one for real?

Try this problem free

Your first session is free. Sign in, and you land on this brief, ready to start.