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:
- Scale- 1 million Users and 100 M URLs
- Latency- 100 ms approximately
- Highly Available
API Design
POST: / v1/ shortURL/{post body}
{
longURL:
}
Get: /v1/ shortUrl/{shortuRL}
High-Level Design
we need 2 services one for shortening of URL nad other for redirection of URL.
Shortening service- uses POST api to create the short URL for corresponding longURL and save it into DB.
RedirectionService- user enters short url and the service fetches the corresponding long url from db and redirects to that URL.
Detailed Component Design
Shortening Service- uses base 62 to shorten the URL. Before shortening the service will check the db if this URL is already present or not. Once a short Url is calculated it is stored in a DB( NOSQL) .
DB- We use No Sql because the data is non relational and we need very fast reads on the data. We will use a Key Value pair DB.
Redirection Service- once a Url is shortened and user enters the short URL in the browser the api GET call will be hit and it will fetch the Long URL from the DB and will redirect to it.