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:
- Low latency on redirections
- High availability
- Horizontal scalability
API Design
- POST /v1/urls
- { "long_url": "https://fakeurl.com?long-query-string", "availability_time": "3D" }
- GET /v1/urls/tiny_url_md5
- Performs redirection to the original 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
- Assuming the eventual consistency is acceptable, a main/replica approach for the database would be a good solution, since the product would receiver a higher read demand than for writes.
- Since the product requires a high availability and horizontal scaling, it should be placed on a cluster with auto scaling strategies applied.
- In that case we need the load balancer in front of it to evenly distribute the load.
- For the low latency requirement a CDN could be used for caching the redirection result, however it would look like an overengineering now, as the database is already working on a cluster providing nodes exclusively for readings and the data associated to each url hash is small, I would prefer to avoid the CDN initially and think about it when necessary, looking for metrics in a monitoring system.