1/12/2024 0 Comments Design tinyurl![]() If two users want to generate two tiny urls for same long string, so in 1st technique there will be two tiny urls with 2 records, but in 2nd technique both will have same MD5 with same first 43 bits so we can have some deduping (to remove duplicate entries from a list or database), so we have to store only one row instead of two row in the database. ![]() Use md5 to generate tinyurl and than check database for collision. Probability of collision - smaller if more bits are taken, but than the length of tiny url gets longer. MD5 is a hashing function that generate 128 bit long hash. We calculate the MD5 of longer url then take the first 43 bits of that md5 and use that to generate the tiny url Problem - For every put you have to do atleast one get. ![]() Otherwise again do put(tiny, long) and repeat Get(tiny) - if both are same than service worker is done Problem - Other worker thread can do the same Get a random tiny url and put tiny url with long url in database. Any number from 0 to 3.5 trillion can be represented by 43 bits.Total combinations - 62^7 - 3.5 trillion (million requests/second - 40 days, 1000 requests/second - 110 years exhaust).This illustration was created using Midjourney artificial intelligence when senior graphic designer Richard Clark asked for a vector illustration depicting 2 students working on laptops in the Baker Library, Dartmouth College. Length of generated tinyURL - 7 characters long Advances in artificial intelligence spark enthusiasm, and some caution.Characters - a-zA-Z0-9 (Use a BASE 62 encoding since A-Za-z0-9 total are 62 characters.).Take shorter url fetch it's corresponding long url and return back long url. ![]() Take longer url generate tiny url and store it in persistance layer and return tiny url
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |