Skip to content
UniCircle
MediumDesignBasics

Design a URL shortener

Question SD-URL-001

Design a service that turns long URLs into short links (like uc.in/aZ3k9) and redirects visitors. Assume 10 million new links a month and 100 times more redirects than creations.

Show the explanation

Model answer outline.

  • Requirements: create a short code for a URL; redirect quickly; links do not change; optional expiry and click counts.
  • Scale estimate: ~4 creations/s on average, ~400 redirects/s (plan for peaks of 10×). Over 5 years ≈ 600M links; at ~500 bytes each ≈ 300 GB.
  • Code generation: 7 base-62 characters give 62⁷ ≈ 3.5 trillion codes. Either encode a unique counter (from a sequence or pre-allocated ranges per server) in base 62, or hash and handle collisions. Counters avoid collisions but are guessable; add randomness if that matters.
  • Storage: key–value lookups by code → a table code → long_url, created_at in a database that scales reads (replicas) or a KV store.
  • Redirect path: cache hot codes (e.g. Redis) in front of the database; respond with HTTP 301 (cacheable) or 302 (if you need every click counted).
  • Analytics: write click events to a queue and aggregate asynchronously so redirects stay fast.
  • Abuse: rate limits and URL scanning for phishing.

Interviewers look for the estimate, the read-heavy caching insight and the code-generation trade-off.

Original UniCircle question. Last reviewed 21 Oct 2026.