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:
- High availability
- Low Redirect Latency
- Horizontal Scalability
API Design
RedirectUrls => /redirectUrls
/redirectUrls/{originalUrl}
High-Level Design
We have users who wants to generate redirect urls for their long url. To create redirect urls we will need redirect urls service which will create redirect urls and sql database to store redirect urls. Since one of non functional requirement is high availability we would use replication pattern of databases as well as replication of services with load balancer. To decrease latency we will use api gateway with caching mechanism as well as cdn to deliver trafic instantly to customers in different locations. If there are too many data to store we would use sharding mechanism and make shards based on original URL for storing redirect urls.
Detailed Component Design
We have redirect urls service which is main component for generating redirect urls. Api gateway in case we need to create more services. Cdn to deliver traffic very fast.