TinyURL/Bit.ly Flashcards

1
Q

Requirements

A
Functional
1. Shorten URL
2. Redirect to original link
3. Custom alias
4. Expire links after some time.
Non Functional
1. Highly available.
2. Redirection should have minimum latency
3. Not guessable links
Extended
1. Analytics
2. Rest API for other services.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Back of envolope calculations

A
  1. 500M new url shortening requests per month
  2. 100 clicks per shortened

Traffic estimates

  1. 500m/month == 200 URLS per second
  2. 50B/month = 20000 URLS per second

Storage
lets say we store 5 years worth of URLS. Then we have 30 billion URLS
Lets say a URL takes 500 bytes, then we need 15 TB of storage.

Bandwidth
For write, we need 200 * 500 == 100KBPS
For read we need 100 * writes = 10 MBPS

For caching 20% of URLS, we would need 0.2 * 20k * 3600 * 24 == 170GB of memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

API definition

A

creatURL(key, original_url, custom_alias=None, user_name=None, expiry_date=None)
deleteURL(key, short_url)
Rate limiter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Data storage model

A

Since these are key value pairs, we should use NoSQL. Something like cassandra will scale well. In this case, we need to store userid:url in another table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Encoding

A

Base36, Base62 or Base64.

Length: 68billion for Base64 with 6 chars.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly