URL shortening deep dive
Last updated
Last updated
As one of the core pieces of the system, we want the URL shortening flow to be logically simple and functional. Base 62 conversion is used in our design. We build the following diagram to demonstrate the flow.
longURL is the input.
The system checks if the longURL is in the database.
If it is, it means the longURL was converted to shortURL before. In this case, fetch the shortURL from the database and return it to the client.
If not, the longURL is new. A new unique ID (primary key) Is generated by the unique ID generator.
Convert the ID to shortURL with base 62 conversion.
Create a new database row with the ID, shortURL, and longURL.
To make the flow easier to understand, let us look at a concrete example.
The distributed unique ID generator is worth mentioning. Its primary function is to generate globally unique IDs, which are used for creating shortURLs. In a highly distributed environment, implementing a unique ID generator is challenging. Luckily, we have already discussed a few solutions