Design a URL Shortener (Bitly, TinyURL)

    A URL shortener maps a long URL to a short slug and redirects on lookup. It is the canonical "read-heavy, write-light" interview problem — the interesting parts are unique key generation, the cache hit path, and avoiding hotspots.

    Web Apps, 8 components, about 35 min

    The full guide covers requirements, estimates, the API, the data model, deep dives, trade-offs, failure modes and the follow-up questions interviewers ask.

    Read the full guide on Substack

    Key points

    • Encoding: base62(counter) — 7 chars covers 3.5 trillion URLs.
    • Counter source: ID ranges leased per server (or Snowflake) avoid a single hot counter.
    • Cache-aside pattern on Redis (slug → URL); 24h TTL on hot links.
    • DB: one PostgreSQL primary + read replicas (~3 TB over 5 years); partition by slug hash later.
    • Analytics writes are async — fire-and-forget to a Kafka topic.

    Sign in to track this guide in your curriculum progress.