MentorNode
Start free
Foundations & Core PatternsMediumdesign-tinyurl

Design a URL Shortener (TinyURL)

Design a highly available distributed service that compresses long URLs into 7-character aliases and redirects users with sub-10ms latency.

Base62 EncodingKey Generation ServiceCache-AsideRead Replicas
Traffic & Capacity Estimates:

100M writes/day (1,200 QPS) · 1B reads/day (12,000 QPS) · 10:1 Read:Write ratio

Functional Requirements

  • •Given a long URL, generate a unique 7-character short URL (e.g. tiny.url/aB3x9Q1).
  • •When visiting a short URL, redirect the client to the original long URL with HTTP 301/302.
  • •Optional custom short alias support.
  • •URLs expire after a configurable duration (default 5 years).

Non-Functional Requirements

  • •Sub-10ms redirect latency for hot URLs.
  • •99.99% high availability (read path must never go down).
  • •Short URL generation must guarantee zero collisions without lock contention.

Back-of-the-Envelope Math

  • 100M new URLs per day = ~1,200 write QPS.
  • 1B redirects per day = ~12,000 read QPS (Peak 25,000 QPS).
  • 5-year storage: 100M * 365 * 5 = 182.5 Billion URLs (~90 Terabytes).

Key Architectural Trade-offs

  • Base62 MD5/SHA256 hashing vs Pre-generated Unique Key Range (Zookeeper / Token Generator Service).
  • HTTP 301 Permanent Redirect (client caches, saves server load) vs HTTP 302 Temporary (server logs click analytics).
  • Cache eviction policy: LRU cache for the top 20% hot URLs serving 80% of traffic.

Click or drag a component onto the canvas, then connect the handles to draw the data flow.

3 nodes · 2 edges

Components · 35

Client & Edge4
Compute & Gateway7
Storage & Caching11
Messaging & Streaming6
Coordination & Ops5
Intelligence2
Canvas overview