AlgoMaster Logo

Design URL Shortener

Ashish

Ashish Pratap Singh

medium

A URL shortener is a service that converts a long URL into a shorter, more manageable version. These short links typically contain a short domain name and a unique identifier (e.g., bit.ly/abc123) that maps back to the original long URL.

Tiny URL

Popular services like TinyURL, Bitly, and t.co (used by Twitter) rely on URL shorteners to:

  • Improve link sharing (especially on character-limited platforms)
  • Track clicks and analytics
  • Redirect users quickly and efficiently

In this chapter, we will explore the low-level design of an url shortener in detail.

Let's start by clarifying the requirements:

1. Clarifying Requirements

Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions, clarify ambiguities, and define the system's scope more precisely.

Here is an example of how a conversation between the candidate and the interviewer might unfold:

1.1 Functional

  • Automatically generate a unique short URL for any given long URL
  • Allow users to optionally specify a custom alias for the short URL
  • Allow users to define and optional expiration dates for short URLs
  • Redirect users to the original long URL when the short URL is accessed
  • Handle URL conflicts gracefully (e.g., when a custom alias is already taken)
  • Track and store the number of times a short URL has been visited

1.2 Non-Functional

  • Uniqueness: Each short URL (including custom aliases) must be unique across the system
  • Extensibility: The design should be flexible enough to support future enhancements
  • Maintainability: Code should follow object-oriented principles, with clean abstractions and clear separation of concerns

2. Core Entities & Algorithm

Premium Content

This content is for premium members only.