Design a URL shortener like Bitly

Design a URL shortener like Bitly

Designing a URL shortener like Bitly is a classic beginner system design interview question. It involves creating a service that turns lengthy URLs into concise, easily shareable links. I’ve chosen this as my first system design exercise for interview preparation. Let's get started!

Functional Requirements

Let's start by defining what our URL shortener needs to accomplish:

  • URL Shortening: Generate unique short URLs from long URLs
  • URL Redirection: Redirect users from short URLs to original URLs
  • Link Analytics: Track click counts, geographic data, and usage patterns

Non-Functional Requirements (Performance)

Our system must handle significant scale with optimal performance:

  • Minimize redirect latency: Users expect instant redirection
  • 100M Daily Active Users: Support massive concurrent usage
  • 1B reads per day = 10k requests per second average
  • 1-5B total lifetime URLs: Plan for long-term growth

API Design

We'll implement a RESTful API with two core endpoints:

URL Shortening Endpoint


POST /api/urls/shorten
Request: 
{ 
  "longUrl": "https://example.com/longurl"
}
Response: 
{ 
  "shortUrl": "https://short.ly/abc123"
}

URL Redirection Endpoint


GET /api/urls/{shortUrl}
Request: Redirect with 302 status code
Response: Location header with original URL

High-Level System Architecture

Image 2 for blog post titled 'Design a URL Shortener Like Bitly'

Database Schema Design

The core of our system is the URL mapping table:

Short URL
- shortUrl: string
- longUrl: string
- userId: string
- createdAt: date
- usedCount: integer

Storage Calculation: With 1KB per record and 5B URLs, we need approximately 5TB of storage for a single database instance.

URL Encoding Strategy

We'll use Base62 encoding (0-9, a-z, A-Z) to generate short URLs:

  • 6 characters: 62^6 = 56B possible combinations
  • Character set: [0-9, a-z, A-Z] for URL-safe encoding
  • Collision handling: Hash original URL with SHA256, then encode

Deep Dive: Generating Unique Short URLs

How to Generate Unique Short URLs?

  • Randomly Assign Characters: Retry and look up database to not have URLs collision
  • Hash: Sha256

Minimize Latency

  • Cache: Most frequently used short URLs
Image 2 for blog post titled 'Design a URL Shortener Like Bitly'


I hope this gives you a high-level overview of URL shortener design!