Showing posts with label baby step to learn system design. Show all posts
Showing posts with label baby step to learn system design. Show all posts

Thursday, August 25, 2016

System Design: Design a URL shortening service

August 25, 2016

Problem statement:

Design a URL shortening service

  • What do you think the requirements are?
  • What is your high level design?
  • You might be asked to implement interesting portions
  • How do you test it? 
Will work on the design very soon.

1. Read the website first:  5 - 10 minutes

stackoverflow.com - how do short urls services work

2. Hired in tech website - the system design process

Step 1: Constraints and use cases
Step 2: Abstract Design

Start from step 1:

System constraints (Do you clarify?)
Use cases ( the list to satisfy?)
Scope system (agree?)

Gather requirements -> design a solution to cover them well.

Use cases:
1. Shortening:
2. Redirection:
3. Custom Url
4. Analytics
5. Automatic link expiration
6. Manual link removal
7. UI or API

And then, discuss and exchange ideas with requirements:
For example, add one more use case 4, and move 4 - 7 out of scope, not for now.

1. Shortening:
2. Redirection:
3. Custom Url
4. High availability of the system

Out of scope: 
4. Analytics
5. Automatic link expiration
6. Manual link removal
7. UI or API

Constraints: 

Top 10 shorten URL services:

Math to figure out, for example: 

15 billion new tweets in twitter, 

All shortened URLs per month: 1.5BN - 10 percent
Sites below the top 3: shorten 300M per month

1. New urls per month: 100MLN - 100 millions request to shortening
2. 
3. 
4. 
20% urls generate 80% traffic -> 1BN request per month -> 10% shortening, 90% redirection.

4. Requests per second: 400+ requests per second (40: shortens, 360: redirects)
5. 6BN urls in 5 years -
6. 500 bytes per URL (100 to 1000 characters per URL)
7. 6 bytes per hash
8. 3TBs for all urls, 36GB for all hashes (over 5 years, not 10 years)
9. how much data goes through each second?
    New data written per second: 40 *(500 + 6): 20K
10. Data read per second: 360 *506 bytes: 180K

scope the problem beautifully - it takes a while, but 15 minutes in the video, with practice, it takes 5 minutes to clear up everything.

Follow up 


Sept. 3, 2016

Spend 2 hours to watch the video, hiredintech.com, the video link is here. System design - scalability, the link is here.


Take some notes here.