Skip to main content
PreparationZone Logo
PrepZone

URL Shortener

Hash long URLs, serve redirects at scale and handle billions of clicks with cache and sharding.

Pass checkpoint below

Read these first

Design a service like sho.rt/abc12 → https://streamhub.com/stream/live_9912. Reads dominate writes 100:1 — cache every redirect, generate short codes without collisions, and handle 100M+ new URLs per month.

Requirements

Functional requirements

  • Shorten a long URL; return a unique short code (6–8 base62 characters).
  • Redirect short URL to original with HTTP 301 (permanent) or 302 (analytics tracking).
  • Optional custom aliases for premium users.
  • Optional expiration and click analytics.

Non-functional requirements

  • Latency: redirect p99 under 50 ms globally.
  • Availability: 99.99% — redirects are the hot path.
  • Scale: 100:1 read/write ratio; 100M new URLs/month; 10B redirects/day.
  • Uniqueness: No two long URLs share a code (or define last-write-wins policy).

Estimation

  • 100M URLs/month × 500 bytes ≈ 50 GB/month storage — trivial for modern DBs.
  • 10B redirects/day ÷ 86400 ≈ 115K redirect QPS average, ~350K peak.
  • Cache hit ratio target: 90%+ → ~35K DB reads/sec at peak — still needs cache + sharding.

URL shortener (AWS)

miss302CLIENT
Click sho.rt/…
NETWORK
CloudFront + …
DATABASE
ElastiCachehot codes
DATABASE
DynamoDBcode → URL
EXTERNAL
Destination302 redirect
CloudFront → ElastiCache → DynamoDB on redirect; API writes on create.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • API design
  • Short code generation
  • Architecture

Test yourself

Answer these before moving on — recall is what makes it stick.