10M links shortened per day -> 100 TPS
100:1 read:write ratio
1B redirects per day -> 10K TPS
100 bytes size of average long url
8 chars for each shortened url hash -> 26^8 possibilities is more than enough. 8 chars is 8 bytes.
To be safe let's assume each row in the db (which will include the long url, the hash, created_at, id) is 200 bytes.
10M links shortened per day * 200 bytes = 2B bytes = 2 GB per day
POST /shortenUrl
request: {longUrl: "https://wikipedia.com/computer_science}
response: {shortenUrlHash: "defabcab"
GET /tinyurl.com/hash
response redirect to long url
So two endpoints - one to shorten a url and one to get a shortened url (and be redirected to its long url)
one table called shortenedUrls
key-value or document based approach can work
schema:
_id: string (will be used as the hash)
long_url: string
created_at: date
expiry_date: date
clicks: int
Cache will be a TTL (time to live).
2 GB per day of writes = 14GB per week = 56 GB per month
so cache ttl can be 1 month easily.
for a write:
For a read:
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
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...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?