🛠️ TalentMe · System Design DISTRIBUTED ARCHITECTURE TEARDOWN

[System Design] Global URL Shortener: 10B QPS Redirects with 99.999% Availability

✍️ TalentMe Architecture Group
📅
⏱️ 5 min read
📊 886 words
[System Design] Global URL Shortener: 10B QPS Redirects with 99.999% Availability
ARCH CHALLENGE
Global Scalable URL Shortener
TARGET SCALE
10B redirects/day (~115k QPS avg, 500k QPS peak), 100M writes/day, P99 < 50ms, 99.999% SLA
TARGET LEVEL
L5 / L6 (Senior / Staff)
CORE PILLARS
High Availability & Consistency

🧮 Back-of-the-Envelope Capacity Estimations

Traffic QPS
Reads: 10B/day = 115,740 QPS avg. Peak (10x): ~1.1M QPS. Writes: 100M/day = 1,157 QPS avg.
Storage Growth
100M links/day * 365 = 36.5B/year. 100 bytes/record = 3.65TB/year. 5-year retention = ~18TB raw, 54TB with 3x replication.
Memory / Cache (80/20)
80/20 rule: 80% of traffic hits 20% of URLs. 20% of 10B = 2B hot URLs. 100 bytes/entry = 200GB. Allocate 512GB Redis cluster for L1 cache.
Bandwidth In/Out
Ingress: 1.1M QPS * 1KB = 1.1 GB/s. Egress: 1.1M QPS * 100B (redirect header) = 110 MB/s. CDN offloads 90% of egress.

📐 High-Level Architecture Topology

flowchart TD
  A[Client] --> B[CDN Edge]
  B -->|Cache Hit| C[301/302 Redirect]
  B -->|Cache Miss| D[API Gateway]
  D --> E[Shortener Service]
  E --> F[Redis Cluster]
  E --> G[Snowflake ID Gen]
  E --> H[PostgreSQL Sharded]
  F -->|Miss| H
  H --> I[Analytics Pipeline]
    

🏛️ Architecture Deep Dive & Component Topology

Ingestion & ID Generation

Writes are decoupled from reads. A centralized Snowflake ID generator (64-bit: 1-bit sign, 41-bit timestamp, 10-bit machine ID, 12-bit sequence) ensures global uniqueness without coordination. Base62 encoding converts the 64-bit ID into a 10-11 character string. Writes go to a single-writer PostgreSQL shard to maintain consistency, then asynchronously publish to Kafka for analytics.

Read Path & Caching

Reads are served by a CDN edge layer. The CDN caches 301 (permanent) redirects aggressively (TTL: 30 days) and 302 (temporary) redirects briefly (TTL: 5 min) to preserve analytics accuracy. On cache miss, requests hit the API Gateway, which queries a multi-tier Redis cluster. L1 Redis (hot keys, 512GB) handles 80% of traffic. L2 Redis (warm keys) handles 15%. Only 5% of requests hit PostgreSQL. Bloom filters are used in the Redis layer to quickly reject non-existent URLs, preventing database lookups for invalid keys.

Partitioning & Sharding

PostgreSQL is sharded by the first 2 characters of the Base62 ID (1,849 shards) to distribute load evenly. Each shard is a primary-replica pair. Reads are routed to replicas, writes to the primary. A consistent hashing ring ensures that data locality is maintained during shard scaling.

💾 Data Models (DDL/Schemas) & API Contracts

SQL DDL

CREATE TABLE urls (
  short_code VARCHAR(11) PRIMARY KEY,
  long_url TEXT NOT NULL,
  created_at TIMESTAMP DEFAULT NOW(),
  expires_at TIMESTAMP,
  click_count BIGINT DEFAULT 0,
  region VARCHAR(10)
) PARTITION BY LIST (LEFT(short_code, 2));

REST Endpoints

POST /v1/shorten
  Body: {"url": "https://example.com/long/path"}
  Response: {"short_url": "https://tinyurl.com/abc123"}

GET /{short_code}
  Response: 301/302 Redirect to long_url

GET /v1/stats/{short_code}
  Response: {"clicks": 12345, "first_click": "2023-01-01"}

🛡️ Extreme Failure Scenarios, Stampede Defense & Self-Healing

Split-Brain & Consistency

In a multi-region setup, split-brain can occur if a region becomes isolated. Mitigation: Use a quorum-based consensus protocol (Raft) for the Snowflake ID generator to ensure no duplicate IDs are issued. For data, use a primary-replica model with a single writer per shard. If a region fails, traffic is rerouted to the healthy region via DNS failover. Data is replicated asynchronously, so there is a risk of data loss (RPO: 1 min). For critical use cases, synchronous replication can be enabled, but this increases latency.

Cache Stampede

When a hot key expires, thousands of requests may hit the database simultaneously. Mitigation: Use a mutex lock in Redis to ensure only one request fetches the data from the database, while others wait. Alternatively, use a probabilistic early expiration (PEXPIRE) to stagger cache invalidations. Bloom filters also help by quickly rejecting non-existent keys, reducing the load on the database.

Disaster Recovery

Multi-region active-active deployment with DNS-based traffic routing. Each region has its own Snowflake ID generator, Redis cluster, and PostgreSQL shards. Data is replicated across regions using Kafka Connect. In the event of a regional failure, DNS is updated to route traffic to the healthy region. RTO: 5 min, RPO: 1 min. Regular chaos engineering tests (e.g., killing a region) are performed to validate the failover process.

🎯 Interview Evaluation Rubric: L4/Senior vs L6/Staff Architect

L4 / Senior Engineer Baseline
Proposes a single-region architecture with a simple Redis cache and PostgreSQL. Uses a UUID or auto-increment ID. Does not consider multi-region failover, cache stampede, or the difference between 301 and 302 redirects. Basic load balancing with Nginx.

L6 / Staff Architect Differentiators
Designs a multi-region active-active architecture with a Snowflake ID generator for global uniqueness. Uses a multi-tier Redis cache with Bloom filters to reduce database load. Differentiates between 301 and 302 redirects for CDN caching. Implements a quorum-based consensus protocol for the ID generator to prevent split-brain. Uses Kafka for asynchronous analytics and data replication. Regular chaos engineering tests to validate failover. Cost optimization by using spot instances for non-critical workloads.

📺 YOUTUBE MASTERCLASS

🎬 Visual Teardown: System Design Interview Question: Design URL Shortener


Watch on YouTube ↗

💡 Key Study Takeaway:ByteByteGo high-frequency FAANG system design teardown of location-based services exploring GeoHash vs QuadTree.
🧭 Master FAANG System Design on TalentMe
Access 69+ production-grade algorithm breakdowns, distributed architecture simulations, and mock interviews.


🚀 Launch TalentMe Architecture Workbench →

SPONSORED PARTNER · 合作伙伴推荐
🛍️ Recommended Gear & Custom Amazon Search for This Topic🔥 4 Curated Picks + Custom Search
⚖️ AirSOTA is a participant in the Amazon Services LLC Associates Program. As an Amazon Associate, we earn from qualifying purchases at no extra cost to you.
探索更多优质技术与商业专栏
返回 💻 大厂系统设计与架构 (System Design Pulse) 专栏或浏览 AirSOTA 知识矩阵

⚡ WEEKLY SOTA DIGEST · DIRECT TO INBOX
📬 Get the AirSOTA Weekly SOTA Briefing (Zero Spam, Unsubscribe Anytime)

Join engineers, parents, and investors receiving our Friday synthesis of AI kernels, AAP baby recipes, and US real estate & S&P 500 deep dives.

🌐 AirSOTA Cross-Domain Ecosystem Synergy

Empowering North American tech talent & families with integrated decision-making across Visa, Career, Wealth, Housing & Education.


Discover more from AirSOTA – Air School Of Thoughts AtoZ

Subscribe to get the latest posts sent to your email.

🏠 首页 | ← TalentMe |