System requirements


Functional:

As a user I would like to provide the original url and get a shortened url

As a user I would like to provide the shortened url and navigate to the original url

The url should be as short as possible

As a user I would like to provide a custom alias to the shortened url to remember or share easily

As an analyst I would like to know how many times the url has been used for analytics purpose




Non-Functional:

The latency to get the shortened url should me as minimal as possible like 100ms

The system should be highly available

The system should be highly scalable

The system can be trade off with consistency for high availability





API design

HTTP

  1. POST CreateShortenedURL(original_url: string, alias:string=None) -> string
    1. {"original_url": "https://www.abc.com/defijslasdfds"}
    2. {"shortened_url": "https://www.xyz.com/123456"}
  2. GET GetOriginalURL(shortened_url: string) -> string
    1. {"shortened_url": "https://www.xyz.com/123456"}
    2. {"original_url": "https://www.abc.com/defijslasdfds"}






High-level design

A client calls the service to generate url, the server that generates the shorten url and store in the database. When doing redirect, the client send the short url to server and server returns the longer url and client has a function to do redirect itself.

We can also have a cache in between server and database for faster retriver of the result.

When there is no url exist, server will simply give error response and client need to know.







Detailed component design

The server can have multiple instances to handle the reuqests coming from the client. And the server will use some algorithm to genereate the short url. The database will consist of 1 table and have reader and writer server.




Database design

Design a table with a specific uuid, the shorten url as another column, the original url as the other column