Design a URL Shortener (TinyURL / Bitly)
A URL shortener converts a long link (like a 100-character article URL) into a compact 7-character key (like tinyurl.com/xyz123) and redirects visitors in under 15 milliseconds.
Live Architecture Studio
Edit components, modify labels, add databases, or redraw connections directly on this canvas:
Loading TinyURL Shortener Blueprint...
Mounting vector diagram elements, nodes, and capacity metrics
Loading TinyURL Shortener Blueprint...
Mounting vector diagram elements, nodes, and capacity metrics
1. Problem & Challenge
Millions of users paste long links and want immediate short URLs. When anyone clicks that short link, the system must instantly look up the destination and redirect them without crashing or mixing up links.
2. Core Building Blocks & Responsibilities
👉 Desliza la tabla para ver roles y responsabilidades| Component | Role | Plain-English Explanation |
|---|---|---|
| DNS & CDN Edge | Traffic Entry | Routes visitors to the closest server geographically so redirection happens with near-zero network delay. |
| Load Balancer (ALB) | Traffic Director | Distributes millions of requests evenly across web servers so no single server gets overwhelmed. |
| Key Generation Service (KGS) | Unique ID Creator | Pre-generates random 7-character Base62 codes (like a-z, A-Z, 0-9) ahead of time so creating a new URL never has collisions. |
| Redis Cache Layer | Ultra-Fast Memory | Stores the top 20% most-clicked links directly in RAM so 80% of redirects don’t even touch the main database. |
| Sharded SQL Database | Permanent Vault | Stores the permanent mapping: Short Hash -> Long URL. Sharded by the first character of the hash. |
3. Step-by-Step Request Flow
User Pastes Long URL
The client sends a POST request with the long destination link to the API Gateway.
Grab Pre-Made Key
Instead of calculating slow MD5 hashes on the fly, the server asks the Key Generation Service for the next available 7-char code.
Save to DB & Cache
The mapping is saved in the database, copied into Redis, and the short link is returned to the user in 10ms.
Visitor Clicks Short Link
The visitor’s browser requests the short link. The server checks Redis first. If found, it returns an HTTP 302 redirect instantly.
4. Architectural Trade-offs
HTTP 301 vs HTTP 302
Chosen: HTTP 302 (Temporary Redirect)
Rationale: 301 is permanently cached by browsers, which stops you from tracking click analytics and link expiration.
Hash on the fly vs Pre-generated Keys
Chosen: Pre-generated KGS
Rationale: Hashing strings often leads to duplicate collisions. Pre-generating unique keys guarantees zero collisions.
Interview Tip
Always mention the 80/20 Pareto principle: 20% of short links will generate 80% of click traffic. Caching that 20% in Redis prevents database bottlenecks.
Explore Related System Blueprints
API Rate Limiter
A rate limiter acts as a digital bouncer at the door of your API, ensuring each client stays within their allowed request limits (e.g. 100 requests per minute) and blocking abusive traffic.
Video Streaming CDN
Streaming high-definition video to millions of smart TVs and mobile phones requires breaking large 10GB video files into tiny 5-second chunks, encoding each into 20 different resolutions, and caching them right inside local ISP networks.
Uber Dispatch Engine
A real-time geospatial dispatch system matches riders with the most optimal nearby drivers using 64-bit H3 hexagonal indexing and 2-second batch optimization, minimizing city-wide pickup ETA and driver idle time.
Stripe Payments Ledger
A resilient financial payments architecture guarantees strict consistency (CP system) using cryptographic idempotency reservation, double-entry balanced postings, and sharded balance locks.
Figma Multiplayer Engine
A real-time multiplayer document engine uses stateful sticky session routing and server-authoritative operational ordering to sync 2D scene graphs across worldwide collaborators without locking.
Twitter Timeline & Feed
A timeline generation system balances high write amplification against fast sub-50ms reads by pushing tweets to followers of regular accounts, while pulling and merging celebrity tweets on-demand.