Design a URL Shortener (TinyURL)

URL Shortener (TinyURL) Architecture
URL shortening services map long, complicated URLs to compact 6 or 7-character string hashes. This guide details how to construct a robust, high-availability shortener.
1. Architectural Goals
1. High Availability: TinyURL must be highly available with 99.99% uptime.
2. Low Latency: Link redirection should take <100ms.
3. Scalability: Handle 100 million new URLs created per day.
2. High-Level Design Overview
We map long URLs to 6-character short hashes using Base62 encoding (a-z, A-Z, 0-9).
To guarantee key uniqueness without database coordination overhead, we implement a Key Generation Service (KGS).
The KGS pre-generates unique string keys and stores them in a KGS DB. Web servers query the KGS for unused keys, ensuring no duplicate mapping can ever occur. We also keep a Redis cache to optimize the redirection path (GET /short_url).
3. Real-World Case Studies & Corporate Optimization
- Microsoft (Bit.ly): Bit.ly uses a highly optimized key generation service to shorten billions of links. They store active mappings in distributed memory caches to perform lookups in single-digit milliseconds.
- Twitter / X: Developed the
t.colink shortener service to wrap all links posted on the platform, leveraging high-throughput distributed lookups to prevent malicious phishing scams. - Amazon: Amazon utilizes its custom shortener
amzn.toto optimize social media links, routing traffic through regional caches for ultra-fast response times.
4. References & Tech Blogs
Prerequisites
- Hashing Algorithms
- Base62 Encoding
Related Topics
Expand your knowledge by learning about adjacent concepts in system design.
Consistent Hashing Basic
Deconstruct routing rings, virtual nodes, and distribution keys.
Event-Driven Scaling with Apache Kafka
Deep-dive into partition offsets, producer acknowledgments, and consumer groups.
Bitly
System design answer key for designing a URL shortener like Bitly, built by FAANG managers and staff engineers.
Cheat Sheet Utility
View and print a concise system design reference card.