How URL Shorteners Work: Designing a Simple and Scalable URL Shortener

(Updated on )

You have probably used a URL shortener many times without thinking about how it works. When you share a link on platforms like LinkedIn, the original URL is often converted into a much shorter URL, such as lnkd.in/...
Services like Bitly do something similar. They take a long URL and generate a short URL that redirects the user to the original destination.

At first, building a URL shortener sounds very simple: take a long URL, generate a short code, store the mapping, and redirect the user. But once we think about scale and multiple users creating URLs at the same time, things become more interesting.

In this article, we will focus on the core functionality of a URL shortener: How do we generate a short URL and use it to redirect users to the original URL?

System Requirements

Functional Requirements

The system should allow a user to submit a long URL and receive a shortened URL. When someone opens the shortened URL, they must be redirected to the original destination.

  • Long URL: [https://www.example.com/a-very-long-page-url](https://www.example.com/a-very-long-page-url)
  • Short URL: [https://short.my/abc123](https://short.my/abc123)

Non-Functional Requirements

The system must be able to handle a very large number of URLs—potentially billions of them. This requirement is critical because the way we generate our short codes needs to work efficiently at a massive scale.

A Simple Approach: Auto-Incrementing Numbers

The first idea that usually comes to mind is simple: assign a unique, auto-incrementing number to every URL.

  • [www.yahoo.com](https://www.yahoo.com) → 0
  • www.iamayham.me → 1
  • [www.example.com](https://www.example.com) → 2

We store this mapping in our database. When a new URL is created, we generate the next number and associate it with the URL.
At first, this looks like a reasonable solution. But imagine that our system eventually stores billions of URLs. If our IDs reach values around 1,000,000,000 or 10,000,000,000, the number itself becomes quite long when represented as a normal decimal string.
For a URL shortener, we want the identifier to be as compact as possible. Can we represent the same number using fewer characters? Yes, by using different number bases.

Why Number Bases Matter

Computers normally work with binary, which uses only two characters (0, 1). Decimal uses ten characters (0-9), and hexadecimal uses sixteen (0-9, A-F).
The larger the number base, the more values we can represent using a single character. Instead of representing a massive number using standard decimal digits, we can use a larger character set to make the visual representation much shorter.

Why Base64 Is Not Ideal

One obvious choice is Base64, which uses 64 characters, but + and / can have special meanings when used in URLs. For a URL shortener, it is safer and simpler to use characters that won't break web formatting. If we remove + and /,we are left with exactly 62 characters.

Enter Base62

Base62 is a number system that uses exactly 62 URL-safe characters: ,, and 0-9.
Instead of storing our long numeric ID directly in the link, we convert the ID into its Base62 representation. The exact output depends on the Base62 character mapping, but a massive number can be represented using just a few characters.
The flow looks like this:

Base 10 to Base 62
Base 10 to Base 62


  1. Receive Long URL
  2. Generate Unique Numeric ID
  3. Convert ID to Base62
  4. Store Mapping in Database
  5. Return Short URL

The Concurrency Problem

What happens if two people try to shorten a link at the exact same millisecond?

If they rely on a basic database counter, the system might read the same current state for both requests and hand them both the exact same ID. Suddenly, two different websites share the exact same short link, breaking the entire routing system.

The Redis Solution

To fix this concurrency issue, we can use an in-memory datastore like Redis.

Redis has an atomic increment feature. Think of it as a strict traffic controller: no matter how many requests flood the server at once, Redis forces them into a single-file line. Every single request is processed in isolation, guaranteeing a completely unique, collision-free ID for every URL.

Conclusion & Source Code

At first glance, a URL shortener is just a simple tool that turns a long link into a short one. But building one capable of handling millions of users simultaneously is a true system design challenge.

By combining Redis to safely generate unique IDs and Base62 to keep those IDs incredibly short, we easily solve the tricky concurrency problem. The result is a lightning-fast, scalable engine ready to handle billions of links.

I built a complete, working version of this system to demonstrate these backend engineering and scalability concepts in action. You can explore the architecture and run it yourself below.

🔗 Check out the full URL shortener project on my GitHub