System Design Primer: Designing a Highly Scalable URL Shortener (Bitly Architecture)

The Classic System Design Architectural Archetype

The URL Shortener (e.g. TinyURL or Bitly) is the quintessential system design interview question. While seemingly straightforward on the surface, scaling this service to support hundreds of millions of daily writes and billions of low-latency reads reveals the core challenges of distributed computing: key generation algorithms, high-throughput caching, collision mitigation, and database sharding.

In this architectural primer, we dissect the system requirements, calculate capacity estimates, evaluate Base62 vs. hashing algorithms, and present an end-to-end resilient architecture.


Capacity Estimations (Back-of-the-Envelope Math)

  • Related Resource: Deep dive into our guide on Top 25 React & Frontend System Design Interview Questions & Answers (2026).
  • Traffic Volume: 100 Million new URLs created per day.
  • Read/Write Ratio: Read-heavy system (10:1 Read-to-Write ratio) $
    ightarrow$ 1 Billion reads per day.
  • Write Throughput (QPS): 100,000,000 / 86,400 $pprox$ 1,160 writes / second.
  • Read Throughput (QPS): 1,000,000,000 / 86,400 $pprox$ 11,600 reads / second (Peak: ~25,000 QPS).
  • Storage Estimation (5-Year Horizon):
    • 100M $ imes$ 365 $ imes$ 5 years = 182.5 Billion URLs.
    • Each record $pprox$ 500 bytes (Short key, Long URL, user ID, timestamp).
    • Total Storage = 182.5B $ imes$ 500 bytes $pprox$ 91.25 Terabytes.
  • Cache Memory (80/20 Rule): 20% of hot URLs generate 80% of daily traffic. Caching 20% of 1B daily reads $pprox$ 100 GB RAM required for Redis cluster.

High-Level System Architecture

High-Throughput URL Shortener Architecture:

Write Flow (Create Short Link):
Client ──► Load Balancer ──► API Servers ──► Token Service (Snowflake ID)
                                   │
                                   ├──► Write to Distributed DB (Cassandra / CockroachDB)
                                   └──► Populate Redis Cache

Read Flow (Redirect Short Link):
Client ──► CDN / Edge ──► API Servers ──► Redis Cache (Sub-ms lookup)
                                                │ (Cache Miss)
                                                ▼
                                         Distributed Database
                                                │ (HTTP 301 / 302 Redirect)
                                                ▼
                                         Original Destination URL

Key Generation: Hash vs. Base62 ID Generator

ApproachMechanismProsCons
MD5 / SHA-256 HashingHash long URL and take first 7 charactersDeterministic from input URLHigh collision probability; requires secondary DB lookup to verify collision
Distributed ID + Base62Generate unique 64-bit Integer (Twitter Snowflake) $
ightarrow$ Encode in Base62
100% collision-free; mathematically boundedRequires centralized distributed ID generator service

Implementing Base62 Encoding

Base62 uses [0-9][a-z][A-Z] (62 characters). A 7-character string allows $62^7 pprox 3.5 ext{ Trillion}$ unique short URLs, vastly exceeding our 5-year requirement of 182 Billion URLs.

# base62.py
CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
BASE = len(CHARS)

def encode_base62(num: int) -> str:
    if num == 0:
        return CHARS[0]
    result = []
    while num > 0:
        result.append(CHARS[num % BASE])
        num //= BASE
    return "".join(reversed(result))

def decode_base62(s: str) -> int:
    num = 0
    for char in s:
        num = num * BASE + CHARS.index(char)
    return num

# Example:
unique_id = 9876543210987
short_token = encode_base62(unique_id) # Returns 'b8e9zTf'

HTTP 301 vs. HTTP 302 Redirect Trade-Off

  • HTTP 301 (Moved Permanently): The browser permanently caches the redirect. Subsequent clicks bypass your servers completely. Advantage: Ultra-fast, reduces server load. Disadvantage: Breaks click analytics and telemetry tracking.
  • HTTP 302 (Found / Temporary Redirect): The browser sends every click back through your server first before redirecting. Advantage: Allows 100% accurate click analytics and geographic attribution. Disadvantage: Increases server traffic load.

Frequently Asked Questions (FAQ)

Which database engine is best for storing billions of URLs?

NoSQL wide-column stores like Apache Cassandra or distributed SQL databases like CockroachDB are ideal. They scale horizontally across clusters, provide high write throughput, and model key-value lookups (short_key -> long_url) naturally with linear partition sharding.


Continue expanding your technical depth with our related engineering guides:

Published by Mohit Kumar under Technical Interview Prep. Read our senior interview guide on Top 25 Node.js Backend Interview Questions & Solutions.

Related Modular Guides & Next Steps

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top