The service will generate concise aliases that redirect to the original longer URLs.
Latency:
Availability
1. Total database capacity:
The database has 4 attributes, userId, tiny url, original url, create timestamp
A record = 20 + 8 + 100 + 8 = 136 bytes,
Assume the index occupied 50% of a record, so the index size is 136 * 50% = 68 bytes
Total = 68 + 136 = 204 bytes
In case of generating 17.28 million tiny urls in a year, DB capacity is 204 * 17.28 * 1,000,000 * 365 = 1.2 PB
2. Bandwidth:
Write bandwidth (generate shorten url):
TPS * (userId + tinyUrl + originalUrl + timestamp) = 136 bytes * 200/s = 27.2 kb/s
Read bandwidth (Get original Urls)
TPS * (userId + tinyUrl + originalUrl + timestamp) = 20,000/s * 136 bytes = 2.72MB/s
3. Cache
Assume the cache occupied 20%, cache = 240 TB
There are two APIs:
Generate tiny url:
Method: Post
endpoint: api/v1/shortenUrl
Request body:
{"originalUrl" : "http://www.example.com/veryLong"}
Response
Success:
{"message": "https://tiny.com/abc123"}
Failure:
{"message": "invalid request"}
http status code:
--- 200 ok
--- 401 invalid request
GetOriginalUrl(String tinyUrl)
Method: Get
Endpoint: /api/v1/get/{tinyUrl}
Response
Success:
{"message" : "https://tiny.com/abc123"}
Failure:
{"message": "url not found"}
http status code:
--- 200 ok
--- 400 not found
The database has below attributes:
Shorter url Service:
Get original url service:
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
If the database and cache both down, the shorter service will not work.
We can generate some shorter url links for people to use when the service is idle. For example, we can generate 10,000 shorter urls in a pool around 3am local time. So in daytime when people request the shorter urls, we can pick the unused shorter urls from the pool, map the shorter url with the original url and return to the users immediately.