BY : SURANI SMIT
From URL Monsters to Bite-Sized Links: The Magic of Shortening
We’ve all been there. You find an amazing article, a hilarious cat video, or that perfect recipe you just have to share with the world. But then you slam face-first into a URL that looks like a runaway keyboard incident. Stringing together enough nonsensical letters and numbers to choke a modem, these monsters make sharing a nightmare.
Instead of princesses needing rescue, the online world has a different kind of hero. It’s not a knight in armor, but a URL shortener. Think of it as a helpful tool that works behind the scenes (sometimes with a cool website design, depending on the service). This tool fights the bad guys: those super long URLs that are annoying to share. With a simple click, the URL shortener shrinks these monsters down to bite-sized links, making them easy to share with friends. But there’s more to this story than meets the eye. Behind the scenes, there’s a whole world of technology and marketing tricks (and maybe a few technical glitches) that make URL shortening work!
How Does URL Shortening Work?
There are two main techniques behind URL shortening:
- Hashing: This method involves converting the long URL into a unique alphanumeric code using a hashing algorithm. The resulting code serves as the shortened URL. It’s important to note that hashing can sometimes lead to collisions, where two different long URLs might get shortened to the same code. To address this, most services employ additional measures to ensure uniqueness.
- Database Storage: Here, the long URL is stored in a database along with a unique identifier. This identifier then becomes the shortened URL. This approach allows for more control and avoids potential collision issues.
URL Shortening System Design – System Design
Terminology
The following terminology might be useful for you:
- Microservices: designing software that is made up of small independent services, which have a specific purpose
- Service Discovery: the process of automatically detecting devices and services on a network
- CDN: a group of geographically distributed servers that speed up the delivery of web content by bringing the content closer to the users
- API: a software intermediary that allows two applications or services to talk to each other
- Encoding: the process of converting data from one form to another to preserve the usability of data
- Encryption: secure encoding of data using a key to protect the confidentiality of data
- Hashing: a one-way summary of data that cannot be reversed and is used to validate the integrity of data
- Bloom filter: a memory-efficient probabilistic data structure to check whether an element is present in a set
URL Shortening and Digital Marketing
URL shortening plays a vital role in digital marketing strategies:
- Social Media Sharing: Shortened URLs are essential for sharing content on social media platforms with character limitations.
- Campaign Tracking: URL shortening services with click tracking features enable marketers to monitor the performance of their campaigns and analyze user behavior.
- QR Codes: Shortened URLs can be integrated into QR codes, making it easier for users to access information by scanning the code with their smartphones.
What is a URL shortening service?
A URL shortening service is a website that substantially shortens a Uniform Resource Locator (URL). The short URL redirects the client to the URL of the original website. Some popular public-facing URL shortening services are tinyurl.com and bitly.com1.
The reasons to shorten a URL are the following:
- track clicks for analytics
- beautify a URL
- disguise the underlying URL for affiliates
- some instant messaging services limit the count of characters on the URL
Choosing a URL Shortening Service
Several URL shortening services are available, each with its own features and functionalities. Here are some factors to consider when choosing one:
- Reliability: Opt for a service with a good uptime record to ensure your shortened URLs function properly.
- Customizability: Some services allow you to create custom short URLs with your brand name.
- Click Tracking: If click tracking is important for your needs, choose a service that offers this functionality.
- Security: Consider the security measures employed by the service to protect your data and the data of your users.
Questions to ask the Interviewer
Candidate
- What are the use cases of the system?
- What is the amount of Daily Active Users (DAU) for writes?
- How many years should we persist the short URL by default?
- What is the anticipated read: write ratio of the system?
- What is the usage pattern of the shortened URL?
- Who will use the URL shortener service?
- What is the reasonable length of a short URL?
Interviewer
- URL shortening and redirection to the original long URL
- 100 million DAU
- 5 years
- 100: 1
- Most of the shortened URLs will be accessed only once after the creation
- General public
- At most 9 characters
Requirements
Functional Requirements
- URL shortening Service similar to TinyURL, or Bitly
- A client (user) enters a long URL into the system and the system returns a shortened URL
- The client visiting the short URL must be redirected to the original long URL
- Multiple users entering the same long URL must receive the same short URL (1-to-1 mapping)
- The short URL should be readable
- The short URL should be collision-free
- The short URL should be non-predictable
- The client should be able to choose a custom short URL
- The short URL should be web-crawler friendly (SEO)
- The short URL should support analytics (not real-time) such as the number of redirections from the shortened URL
- The client optionally defines the expiry time of the short URL
Non-Functional Requirements
- High Availability
- Low Latency
- High Scalability
- Durable
- Fault Tolerant
Out of Scope
- The user registers an account
- The user sets the visibility of the short URL
URL Shortener API
This is the improved Version of the Initial URL Shortening Service we built in class. This can be directly deployed using Vercel
“For those interested in learning more about URL Shorting, I highly recommend checking out my teacher’s GitHub profile: SAMARANJIT-GHOSE. They have a wealth of experience and resources available, including URL-Shorting.”
LINK: https://github.com/smaranjitghose/coolurl