System Design of Tiny Url

Why do we need URL shortening

For example, if we shorten this page through TinyURL:

https://www.educative.io/collection/page/5668639101419520/5649050225344512/5668600916475904/

We would get:

http://tinyurl.com/jlg8zpc

 

How to generate Tiny URL

Suppose a tinyURL is 7 characters long and each character can be taken from following 62 alphabets

  • a-z = 26
  • A-Z = 26
  • 0-9 = 10

Generate 62 is CAN. 7 ^ WE (= ~ 3.5 of Trillion ) tinyURLs HAVING. 7 characters from alphabets 62 is length. (Divided by the estimated number of pieces produced per day can estimate how long url depleted and storage space according to the estimated required length url)

 

System Design

 

 

Detail

The self-energizing ID to generate a corresponding coded base 62 url, so collision will not occur. If multiple machines concurrently sequentially generated sync id distributed lock requires very low efficiency. So consider using a range counter of the id range cut.

E.g:

1 -- 100k ~ 200k

2 -- 200k ~ 300k

n -- ...

 

Implemented using zookeeper range counter, as a final consistency nosql zookeeper as high availability and scalability.

When the webserver to generate url to access the cache if there is no hit to zk application range will be synchronized to the results of persistence and cache. If the server is down corresponding range is erased.

 

 

reference:https://www.youtube.com/watch?v=JQDHz72OA3c&list=LLzFCWqxDhIffTUi1VOx2iqw&index=6&t=0s

 

Guess you like

Origin www.cnblogs.com/lnas01/p/11240031.html