Skip to content
    Architecton

    REAL-WORLD DESIGNS · 12 MIN

    Design a URL Shortener

    Put it together: turn long links into short codes that redirect millions of times a day.

    ARCH explains

    • Requirements: create short link, redirect fast, very read-heavy (≈100 reads per write).
    • Generate codes by base-62 encoding a unique ID; store code → URL in a key-value store.
    • Cache popular codes, put a load balancer in front, and replicate the store for reads.

    Real world: Links shared in WhatsApp messages and posters.

    Code

    ALPHA = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    def encode(n):
        s = ""
        while n:
            n, r = divmod(n, 62)
            s = ALPHA[r] + s
        return s or "0"
    print(encode(125), encode(3844))
    Output ›
    21 100
    Try it in the online compiler →

    Checkpoint quiz

    A URL shortener is mostly…