Skip to main content
BLUEPRINT #05Core Infrastructure

Design a Distributed URL Shortener (TinyURL)

Target AWS Architecture:DynamoDBS3ElastiCacheKinesis
10-Stage Structure:1. Requirements→2. Sizing→3. Topology→4. Data Model→5. AWS Topology→6. Deep-Dive→7. Failures→8. SRE Playbooks

1. Problem Statement & Scope

System Mission

Design a highly scalable, fault-tolerant, low-latency URL Shortening service (similar to TinyURL or Bitly) that transforms long HTTP URLs into compact 7-character aliases, handles billions of redirects with sub-10ms latency, supports custom aliases, expiration TTLs, and real-time click analytics.

Functional Requirements

  1. URL Shortening (POST /v1/urls): Given a long URL, generate a compact, unique 7-character alias (e.g. https://hi.link/aZ9k2Lq).
  2. URL Redirection (GET /{short_code}): Given a short code, instantly redirect the client to the original long URL with minimum latency.
  3. Custom Aliases & Expiration: Allow users to specify custom short aliases (e.g. https://hi.link/summit2026) and optional expiration timestamps ().
  4. Click Analytics: Asynchronously aggregate click metrics (total clicks, referrer, client country, timestamp).

Non-Functional Requirements (SLAs/SLOs)

  • High Availability: 99.999%99.999\% uptime for redirection lookups (Read Path is mission-critical).
  • Ultra-Low Latency: Read Redirection Latency <10Β ms< 10\text{ ms}; Write Latency <50Β ms< 50\text{ ms}.
  • Durability: 99.999999999%99.999999999\% (11 9s) zero URL mapping loss guarantee.
  • Read-to-Write Ratio: Heavy read bias of 100:1100:1 (100 redirections per 1 new URL shortened).

2. Capacity & Scale Estimation

Traffic Calculations

  • New URL Creation Rate (Writes):
    • 100 Million new URLs created per month.
    • Average Write : WriteΒ QPS=100,000,00030Γ—86,400β‰ˆ38.6Β writes/sec\text{Write QPS} = \frac{100,000,000}{30 \times 86,400} \approx \mathbf{38.6\text{ writes/sec}}
    • Peak Write (5Γ—5\times burst): 200Β writes/sec\mathbf{200\text{ writes/sec}}.
  • Redirection Traffic (Reads at 100:1 Ratio):
    • Average Read : ReadΒ QPS=38.6Γ—100β‰ˆ3,860Β reads/sec\text{Read QPS} = 38.6 \times 100 \approx \mathbf{3,860\text{ reads/sec}}
    • Peak Read (3Γ—3\times burst): 11,580Β reads/secβ‰ˆ12,000Β QPS\mathbf{11,580\text{ reads/sec}} \approx \mathbf{12,000\text{ QPS}}.

Storage & Memory Estimation (10-Year Horizon)

  • 10-Year URL Volume: 100MΒ URLs/monthΓ—12Β monthsΓ—10Β years=12Β BillionΒ URLs100\text{M URLs/month} \times 12\text{ months} \times 10\text{ years} = \mathbf{12\text{ Billion URLs}}
  • Record Size:
    • short_code: 7 Bytes.
    • long_url: 500 Bytes average.
    • user_id: 16 Bytes.
    • created_at / expires_at: 16 Bytes.
    • Metadata & Overhead: 61 Bytes.
    • Total per Record: β‰ˆ600Β Bytes\approx 600\text{ Bytes}.
  • 10-Year Database Storage: 12Γ—109Γ—600Β Bytes=7.2Β TB12 \times 10^9 \times 600\text{ Bytes} = \mathbf{7.2\text{ TB}}
  • 3-AZ Multi-Region Replicated Storage: 7.2Β TBΓ—3=21.6Β TB7.2\text{ TB} \times 3 = \mathbf{21.6\text{ TB}}
  • In-Memory Cache Sizing (80/20 Pareto Rule):
    • Daily active redirection requests: 3,860Γ—86,400β‰ˆ333Β MillionΒ requests/day3,860 \times 86,400 \approx 333\text{ Million requests/day}.
    • 20%20\% hot URLs generate 80%80\% of traffic: DailyΒ UniqueΒ HotΒ URLs=333MΓ—0.20Γ—600Β Bytesβ‰ˆ40Β GBΒ RAM\text{Daily Unique Hot URLs} = 333\text{M} \times 0.20 \times 600\text{ Bytes} \approx \mathbf{40\text{ GB RAM}}
    • Allocate an with 64Β GBΒ RAM64\text{ GB RAM} (easily caching 100% of daily hot URLs).

Base62 Encoding & Hash Space Math

A short code consisting of alphanumeric characters [0-9, a-z, A-Z] has a character alphabet size of: Base=10+26+26=62\text{Base} = 10 + 26 + 26 = 62 For a 7-character string, the total unique URL capacity is: 627=3,521,614,606,208β‰ˆ3.52Β TrillionΒ uniqueΒ URLs62^7 = \mathbf{3,521,614,606,208} \approx \mathbf{3.52\text{ Trillion unique URLs}} At 100M100\text{M} URLs/month, 3.52Β Trillion3.52\text{ Trillion} provides over 2,900 years of collision-free namespace capacity.


3. AWS-First High-Level Architecture

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Part 2: Production Deep-Dive Locked1 Coin = 24 Hours

Unlock Complete Architecture & Production Runbooks

Your Balance:40 Coins

You have explored the free architectural preview (~42%). Spend 1 Coin to unlock the remaining 7 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
4. API Interface Design
5. Data Models & Storage Architecture
6. Component Deep Dives & Workflows
7. Architectural Trade-Off Matrix & Primitive Links
8. Critical Edge Cases & Distributed Failure Modes
9. Production Pitfalls & Anti-Patterns (The "Gotchas")
10. Production Runbook & Operational Best Practices
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure