Let's assume daily user is :
100Million
Short url length is 7 char
and long URL is 128 chars
Total record for 10 years
100M*365*10 --> 365000M--> 365Billion
Lets assume average size of each row is 100Bytes
Than --> 365B*100 --> 36500GB --> 35.5TB
Lets say we have 3 replicas
3*35.6TB --> ~100TB
Transaction per second
100M/86400 --> 1100 TPS
Lets say 10:1 is read and write ration
so Overall TPS will be 1100*10 --> 11000TPS
We are using base 62 to convert short url
Total unique possibilities is. 62^7 --> 3.5Trillion
Api to generate short URL
Method : POST
API : /v1/generateUrl
Request --> { url : "input url"}
Response --> shortUrl
API to get long url -->
Method : GET
API : v1/getUrl/{shortURL}
Response : long url
Header will redirect status code i.e : 301
Table urls{
string : shortUrl --> Primary Key /partition Key
string : url --> unique key
date : createdAt
}
Generate short URL :
Generate short url flow :
1.Client call to back-end service.
Get long URL :
1.Client call to back-end service.
Client --> API Gateway
API to URLGeneratorService and vice versa.
URLGeneratorService to Zookeper --> to get next number.
URLGeneratorService to cache --> to lookup shortURL
URLGeneratorService to Db --> To read and write data
Client --> Who is requesting for data.
API Gateway -->
URLGeneratorService -->
Database
Cache :
Zookeeper :
Data base: As we don't need ACID property also required a scalability is priority, so NOSQL Db will be better choice. We can use Cassandra (If we have internal expertise and have strong management team), or DyanomoDB (If cost not matter)
Also DynamoDb will be help for CDN setup(If we have CDN also in AWS).
Cache : As we required 11K TPS read and write we can user Redis as distributed cache.
Put TTL least use key.