Encode a long URL to a short URL.
Decode a short URL to a long URL.
Stable.
High Availability
DAU =~100M
Assume:
a.Write:
0.1 write/user a day
Average write QPS = 100M*0.1/86400 =~100
Peak write QPS = 100*2 = 200
b.Read:
1/user a day
Average Read QPS = 100M*1/86400 = ~1000
Peak Read QPS = 1000*2 = 2000
c. Storage
100Byte/url
100M*0.1*100Byte = ~10G
We can use NoSQL
Table:
1.URL(Long to short) mapping table
Column: ID(int), LongUrl(varchar), shortUrl(varchar)
Index on LongUrl
2.URL(Short to long) mapping table
Column: ID(int), shortUrl(varchar), LongUrl(varchar)
Index on ShortUrl
a. Create a short URL
b.Visite a short URL
1.Database bases on the sequential ID to sharding horizally
Explain any trade offs you have made and why you made certain tech choices...
Database use Master-Slave to make sure the stablity when a database server is down.
Master handles write and slaves handle read. If the Master is down, randomly pick a slave to be master.
1.reduce fetching time:
a. cache (use memcached) to store latest requested short url
b.cdn to get data by closest location