![]() Of course, we can involve one lock sub system to help us accomplish this requirement. To make this TinyURL system distributed, we need to ensure the auto incremental number used to generate the short url is synchronous with the whole cluster. Remember how do we transfer one binary number to one decimal number? Yes, we can do the similar thing to transfer this unique decimal number to a 62 hex number, where each number can be represented by a character in. Then, how do we transfer this unique number to a short url and ensure there is an one to one relationship between them too? Since the number is auto incremental in the system so that there is one to one relationship between long url and the unique number. We first transfer the long url to a unqiue number in our system, then transfer the unique number to a short url. Using an auto incremental number as the intermediary is quite useful in this case. I know the possibility is low if using modern hash algorithm, but seems like we have better choices. It is possible two long urls may have the same hashed short url. But one thing need to be remembed that this solution doesn’t prevent the hash collisoin for one hundred percent. ![]() How about using one hash algorithm directly on the long url, get a short string and create one map using the short string as key and the long string as value? This solution sounds doable and straight forward. It looks quite easy, the key point is just to create a bidirectional mapping between short url and long url. This TinyURL system needs to provide two basic functions, return a short url based on a given long url and return the corresponding long url based on previously return short url. This post is to record the idea and tips what I learnt from websites to solve this problems. TinyURL system design is a fairly classic interview question since it can test the abilities of one interviewee from many aspects.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |