Real-World Production Deep Dives: URL Shortener

โš ๏ธ Not yet source-checked. These case studies summarize public engineering posts and talks, and some details may be simplified or wrong. Before you repeat a specific number or design in an interview, check it against the company's own write-up. Found an error, or a source that confirms a section? Add it to the tracking issue. Sourced fixes are the most welcome contribution here.

Deep-dive architectural dissections of how Bitly and Twitter / Google (t.co & goo.gl) scale URL shorteners to billions of clicks, balance 301 vs 302 redirects, and protect against malware and phishing.


๐Ÿ”— Deep Dive 1: How Bitly Scales URL Shortening (10 Billion+ Clicks/Month)

1. Production Context & Scale

2. The Core Problem at Bitly Scale

3. Bitly's Engineering Architecture

[ User Clicks Short Link: bit.ly/3xK9yZ ]
                   โ”‚
                   โ–ผ
       [ Global Anycast Edge Proxy ]
                   โ”‚
       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
       โ–ผ (Cache Hit: 99%!)      โ–ผ (Cache Miss: 1%)
 [ Distributed Cache (Redis) ]  [ Relational / NoSQL DB ]
       โ”‚                               โ”‚
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
        HTTP 301/302 Redirect to Long URL
                      โ”‚
                      โ–ผ (Async Telemetry Beacon)
       [ Kafka Click Analytics Stream ]
                      โ”‚
                      โ–ผ
       [ ClickHouse OLAP Column Store ] โ”€โ”€> Real-Time Customer Dashboard

A. ID Generation via Distributed Sequence Generators

To completely eliminate hash collisions without locking:

  1. Bitly uses a distributed unique ID generator (e.g., ZooKeeper-coordinated counter blocks or Snowflake IDs) producing 64-bit auto-incrementing integers.
  2. The integer is converted to a short alphanumeric token using Base62 Encoding ([a-zA-Z0-9]):
    • A 7-character Base62 string yields:
627 โ‰ˆ 3.52 ร— 1012 unique combinations (3.5 trillion URLs)

B. Multi-Tier Caching for 99%+ Hit Ratio

C. Asynchronous Analytics Pipeline via Kafka & ClickHouse


๐Ÿ›ก๏ธ Deep Dive 2: How Twitter & Google Handle Short URLs (Malware Defense & 301 vs 302)

1. Production Context & Scale

2. Google Safe Browsing Integration

3. The 301 vs 302 Architectural Decision

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ HTTP 301: Moved Permanently                                โ”‚
โ”‚  - Browser caches redirect aggressively on user's device.  โ”‚
โ”‚  - Pros: Subsequent clicks bypass shortener server! (0ms)  โ”‚
โ”‚  - Cons: Shortener loses all analytics on repeat clicks!   โ”‚
โ”‚          Cannot revoke compromised or malicious links!     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ HTTP 302: Found (Temporary Redirect)                       โ”‚
โ”‚  - Browser never caches; sends every click to shortener.   โ”‚
โ”‚  - Pros: 100% accurate click analytics & malware checks.   โ”‚
โ”‚  - Cons: Slight increase in server load.                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โš–๏ธ Comparative Architecture Matrix

Architectural Dimension Bitly Enterprise Architecture Google / Twitter (t.co)
Token Generation Distributed 64-bit ID -> Base62 encoding Cryptographic hashing + Internal safety validation
HTTP Redirect Code Configurable (301 for SEO / 302 for Analytics) Strictly 302 Temporary (Mandatory inspection)
Security Layer Machine learning spam filters + Third-party abuse APIs Native Google Safe Browsing API integration
Analytics Engine Apache Kafka + ClickHouse OLAP Internal Pub/Sub + BigQuery / MapReduce
Mobile Integration Universal Links / Deep-linking SDK Firebase Dynamic Links with deferred app store routing

๐ŸŽฏ System Design Interview Takeaways

  1. Explain Why Base62 via ID Generator Beats MD5/SHA: Explain that hashing algorithms (MD5/SHA256) cause collisions when truncated to 7 characters. Generating unique integers (Snowflake/ZooKeeper) and converting to Base62 guarantees zero collisions and requires no database lookups.
  2. The 301 vs 302 Redirect Tradeoff: When an interviewer asks which HTTP code to return, articulate the exact tradeoff:
    • 301 Moved Permanently: Reduces server load because the browser caches the redirect, but destroys analytics and prevents malware takedowns.
    • 302 Found: Ensures 100% analytics capture and immediate fraud revocation, making it the industry standard for commercial shorteners.
  3. Decouple Analytics from Redirects: Always emphasize that redirecting the user and tracking analytics must be asynchronous (via Kafka/PubSub) to preserve sub-20ms redirect latency.

๐ŸŽฌ Deep Dive 3: How Netflix Uses URL Shortening (TV Activation & Deep-Linking)

1. Production Context & Scale

2. Architecture: Low-Latency Edge Redirection & Attribution