High-Scale Architecture & Distributed Systems

System Design Studio

Deep architectural breakdowns: functional scopes, capacity planning, distributed caching, database indexing, and scaling trade-offs.

Architecture BlueprintMedium

Design a High-Throughput URL Shortener (TinyURL)

Scale Target: Generate short 7-character unique aliases for long URLs, handle 100M new URLs/month, and redirect in <10ms.

Functional Requirements

  • Given a long URL, return a unique 7-character short URL.
  • Accessing the short URL redirects the client via HTTP 301/302.
  • Custom alias support and link expiration dates.

Non-Functional Requirements

  • High read-to-write ratio (100:1 read heavy).
  • Ultra-low latency (<10ms for redirects).
  • High availability (99.99%).

High-Level Architecture

DNS -> CDN / Edge -> Load Balancers -> Shortener API Gateway -> Redis Read Cache -> Distributed SQL/NoSQL Database (Turso/Postgres/Cassandra) with a distributed token range generator or Snowflake ID generator.

Capacity Assumptions: 100M writes/month ≈ 40 writes/sec. 10B reads/month ≈ 4,000 reads/sec (peak 10,000 reads/sec). 7 chars Base62 = 62^7 ≈ 3.5 trillion URLs.

Core System Components (4)

API ServiceNext.js / Go

Validates long URL, generates Base62 alias, persists to database and cache.

Distributed Counter / Key GenSnowflake / Redis Atomic

Pre-generates unique 64-bit IDs without DB collisions.

Cache LayerRedis Cluster

Stores Top 20% most accessed URLs (Pareto principle).

Persistent StorePostgreSQL / Turso

Stores mapping: id, short_key, long_url, user_id, created_at, expires_at.

Bottlenecks & Trade-Offs

Trade-off #1: HTTP 301 (Permanent Redirect) vs 302 (Temporary): 301 caches in browser, saving server load but losing click analytics; 302 hits server on every click for accurate tracking.
Trade-off #2: Base62 encoding of an auto-incrementing ID vs MD5 hash truncation: MD5 requires collision resolution; Base62 of 64-bit ID guarantees zero collisions.

Key Engineering Takeaways

  • Separate ID generation from encoding to guarantee zero collision handling overhead.
  • Caching hot redirects eliminates 99% of read queries from hitting persistent disk.