Requirements
Functional Requirements:
- Create a short URL for a given long URL.
- Return the long URL associated with a given short URL
- The short URL cannot be updated
Non-Functional Requirements:
- Low latency: Redis cache for frequently requested URLs
- High availability:
- one data center per region (US+South America, Europe, Asia)
- Anycast on DNS routing to have geo locality
- Each region has it's own DB (sharding) with replication
- Shorten service is a layer with multiple instances - traffic distibuted per data center/region through LB and API Gateway
- Stateless shorten service and Kubernetes to scale out when needed
- Reliability
- Short URL lenght should be minimum
- Persistence: mapping should be available for 5 years
- 1 000 000 new short URLs created per day
API Design
- Request for Short URL creation: POST /api/v1/shorten
- Request parameter: long URL
- Response returned: short URL, http success code (200)
- Request to access the long URL page: GET /api/v1/shortUrl
- Response is HTTP redirect 301 (for easing load on servers) or 302 (for analytics and insights on marketing campaigns) and the long URL
High-Level Design
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
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.