・High Availability
・Low Latency
・Scalability
1. Create Short URL
- Endpoint: POST /api/v1/shorten
- Request Body: { "long_url": "https://example.com/very-long-page" }
- Response: { "short_url": "https://tiny.url/abc123" }
2. Redirect
- Endpoint: GET /{short_url_id}
- Response: 302 Redirect to long_url
The system follows a standard microservices architecture to ensure high availability and scalability.
1. Load Balancer: Distributes incoming requests to multiple web servers to prevent bottlenecks.
2. Web Servers: Handles incoming API requests for URL shortening and redirection.
3. Cache (Redis): Stores frequently accessed mappings to ensure low-latency redirection.
4. Database: Provides persistent storage for all URL mappings.
1. Short ID Generation
To generate a unique short ID, we use an auto-incrementing counter converted to Base62. A 7-character ID provides enough combinations for our scale.
2. Database Selection
We choose a NoSQL database like DynamoDB because it handles high write throughput and horizontal scaling better than traditional RDBMS.
3. Caching Strategy
Since the read-to-write ratio is high, we use an LRU eviction policy in Redis. This keeps popular URLs in memory, reducing the load on the database.