← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 001 · Fundamentals and estimation

Design a URL Shortener

Easy 30 min

Design a service like a link shortener. Users submit a long URL and receive a short code. Anyone opening the short link is redirected to the original URL. Reads vastly outnumber writes, and a code must never resolve to the wrong destination.

Functional requirements

  • Create a short code for a long URL
  • Redirect a short code to its original URL
  • Optionally expire links
  • Count clicks per link

Non-functional requirements

  • Redirect p99 latency under 120 ms
  • 99.9% availability for redirects
  • Codes are unique and never reused for a different URL

Constraints and scale

  • 100 million new links per month
  • 100:1 read-to-write ratio
  • Links are kept for 5 years

You will practise

  • Estimate QPS and storage
  • Place a cache on a read-heavy path
  • Generate unique IDs across instances
Show 3 hints
  1. Work out write QPS first: 100M / (30 × 86 400)
  2. How would three API instances avoid issuing the same code?
  3. Click counting does not need to be on the redirect path

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • Cache hit rate collapsesA viral campaign sends traffic to millions of brand-new links. The cache hit rate drops from 95% to 12% and the database is overwhelmed.
  • Database primary goes downThe primary database node fails at peak traffic.

Run them from the workspace once your design is in place.