Requirements
Functional Requirements:
- Shorten a long URL → generate a unique short URL
- Redirect short URL → original URL
- Optional:
- Custom aliases
- Expiration time
- Analytics (click count, geo, etc.)
Non-Functional Requirements:
- High availability (redirect must be fast)
- Low latency (redirect in ~10–50ms)
- Scalability (millions/billions of URLs)
- Durable storage
API Design
Create Short URL
POST /shorten
{
"long_url": "https://example.com/very/long/url"
}
Response:
{
"short_url": "https://short.ly/abc123"
}
Redirect
GET /abc123
→ 302 Redirect to original URL
High-Level Design
Client
|
API Gateway
|
| |
Write Service Read Service
(Create short) (Redirect)
| |
Database <--> Cache (Redis)
Detailed Component Design
[API Gateway]
|
v
[Shorten Service] -----> [ID Generator]
| |
v |
[URL Store (DB)] <-------------+
|
v
[Cache (Redis)]
[Redirect Service] ---> [Cache] ---> [DB]
[Analytics Pipeline]
|
v
[Queue] -> [Stream Processor] -> [Analytics DB]