Requirements
Functional Requirements:
- Create a short URL for a given long URL.
- Return the long URL associated with a given short URL.
Non-Functional Requirements:
- Redirect should happen in <50ms
- Target 99.99% uptime
- Assume 100M urls per month and 10B redirects per month
- Read-heavy
- A URL created should never be lost
- Cache aggressively to reduce database load
API Design
- A POST endpoint to take in long urls and return the shortened version
- A GET redirect
- A GET for metadata (optional)
High-Level Design
- API Gateway / Load Balancer
- URL Creation Service
- Redirect Service
- Cache
- URL Database
- ID Generator
Detailed Component Design
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.