write operation:
POST https://api.tinyurl.com/v1/url
{
long_url: "google.com"
auth_token: "*"
}
Read operation
GET https://tinyurl.com/url/jIkND9
reponse code 302, because we might want to track user activity for analytics (301 will cache the url and redirect automatically without routing the api to our system.)
short_url(key) | long_url | hash_value | created_by | created_at
jIkND9 | google.com
Write flow:
Read flow:
DB consistency strategy:
By using quorum theorem
We guaruntee strong consistency of the system and fast read.
Load balancer: We use consistent hashing to guarantee even distribution
ID generator:
To avoid clashing, we can use a simliar strategy to Twitter snowflake ID generator system by puting the ID into different part like timestamp, machine id, cluster id, namespace etc.
By using quorum theorem
We guaruntee strong consistency of the system and fast read.
reponse code 302, because we might want to track user activity for analytics (301 will cache the url and redirect automatically without routing the api to our system.)
etc.
If user try to read an non existing short url, we should return 404.
To avoid single point of failure, we need redundancy of different parts of the system like servers, id generators, data base
If our service is to be expanded to global, we might want a different data center for faster response.
The Server Cluster is set to be easily scaled horizontally.
We might want to introducing sharding if the traffic is beyond expection and storge spacc gets challenged.
(also introduce 7 digits short url when we are scaling out)