System design
In this section, we will explore solution options, bottlenecks, problems, mitigations, and high-level architecture diagrams. First, let’s start with identifying what the core challenge here is.
Core challenge
The core challenge in this design problem is as follows: how do we generate unique URLs? There can be various solutions. Let’s explore one at a time and see what are the pros and cons of each one and let’s arrive at the most suitable one.
Option A – generate a random URL
Given a long URL, generate a random short URL and check whether exists in the database (DB). If it exists, then generate another random URL and keep doing it until we find that the entry doesn’t exist. If it doesn’t exist, then store this new entry in the DB as a key-value pair: {short_url ->
long_url}
.
There are a few problems with this approach:
- As you can see, there has to be at least one check done against the DB to find whether...