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 latency
- horizontal scalability
API Design
- one api to generate the short url
- one api to retrieve long url with the short url
High-Level Design
Our clients hit our load balancer (reverse proxy). We have two servers running for high availablility, with one db and one cache. for get api they hit the cache first then the db
Detailed Component Design
- the logic of generating the short url. in redis we can have a counter set to get the latest id(unique number) of db records. for this id we can generate base64 string, which would be our short url. in the db, store the data for the id, short url and the long url
- When user tries to retrieve the data, see if available in cache, else fetch from db. from short url, decrypt base64 get the id, since it will be indexed it will be retrieved faster from db
- cache we can have persistance so that the counter will be upto date and can be used by both servers, and no duplicate id will be generated. we can use LRU cache policy to maintain high cache hit