If latency budgets leave no room for synchronous retries, serve redirects from Anycast Edge POPs with L1 LRU + regional Redis, coordinate writes via pre-allocated Base62 key-range shards, and replicate asynchronously across regions.
TL;DR30-second simplified summary▾
Anycast Edge POPs pair L1 in-memory LRU caches with regional Redis Clusters to serve 98% of 100K RPS reads locally in <15ms. Multi-region write coordinators lease disjoint Base62 prefix shards ([a-g]*, [h-n]*, [o-z]*) so regions write locally with zero WAN locks.
Active-active Cassandra/DynamoDB replicates globally, with origin-encoded prefixes enabling single-hop fallback on fresh misses and Pub/Sub purges enforcing phishing takedowns in seconds.
62^7 = 3.52T combinations), pairing collision-free writes with edge-cached HTTP 301/302 redirection.Traffic & 5-Year Storage Sizing.
Why this matters: Calculate read/write QPS, 5-year storage footprint, and Redis cache memory.
1K writes/sec * 86,400s * 365d * 5y = ~157.7B URLs.
At ~500 bytes per record (short_code, long_url, user_id, created_at, expires_at), raw data is ~79TB (with 3x replication = ~237TB).
100K RPS & 5-Year Storage Model
1.7-Char Base62: 62^7 = 3.52T easily covers 158B URLs (<5% utilization over 5 years).
2.Bandwidth: 100K RPS * 500B redirect response = ~50 MB/s (400 Mbps) aggregate egress.
79TB of 5-year data and an 8.5GB hot working set dictate NoSQL sharding plus regional Redis.
Anycast Edge POPs & L1/L2 Regional Caching.
Why this matters: Achieve <15ms global p99 redirect latency across continents.
Anycast BGP routes users to the nearest Edge POP.
Each POP maintains an L1 in-memory LRU cache (100K hottest global slugs, <0.2ms) and queries a regional L2 Redis Cluster (<2ms) on L1 miss.
Anycast POP + L1/L2 Cache Hierarchy
1.Viral Absorption: L1 LRU absorbs 50K+ RPS single-link spikes without hitting Redis.
2.Negative Cache: Edge Bloom filters + 60s 404 cache block invalid-code floods.
Three-tier Anycast + L1 + L2 caching keeps 98% of redirects within the local metro region.
- Problem
- How to implement Design a Global URL Redirection Engine (100K RPS) without hitting unbounded tail latency, state divergence, or operational fragility.
- Naive Solution
- Use a single unpartitioned path with unbounded retries and synchronous global coordination.
- Why It Fails
- Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
- Alternatives
- Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
- Engineering Decision
- If latency budgets leave no room for synchronous retries, serve redirects from Anycast Edge POPs with L1 LRU + regional Redis, coordinate writes via pre-allocated Base62 key-range shards, and replicate asynchronously across regions.
- Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
When Design a Global URL Redirection Engine (100K RPS) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?
Multi-Region Write Coordinator & Key-Range Shards.
Why this matters: Generate globally unique short codes across US, EU, and APAC with zero cross-region locks.
Think of Multi-Region Write Coordinator & Key-Range Shards as the intuition layer for Design a Global URL Redirection Engine (100K RPS): Generate globally unique short codes across US, EU, and APAC with zero cross-region locks.
Running cross-continent Paxos on every POST /shorten would add 150ms+ write latency. Instead, a central ZooKeeper/etcd coordinator assigns disjoint prefix ranges to each region (e.g., a-g* to US, h-n* to EU, o-z* to APAC), and regional write workers lease 1M-ID sub-blocks locally—generating globally unique codes in <1ms.
Disjoint Regional Key-Range Shards
1.Zero Cross-WAN Write: Regions issue short codes completely independently with zero WAN round-trips.
2.Custom Vanity Slugs: Only user-chosen custom aliases use conditional quorum writes (LWT/ConditionalPut).
Disjoint regional key-range shards eliminate cross-region consensus from the standard write path.
Active-Active Geo-Replicated NoSQL & Read-Your-Writes.
Why this matters: Replicate mappings globally while ensuring a creator's immediate test click never 404s.
Think of Active-Active Geo-Replicated NoSQL & Read-Your-Writes as the intuition layer for Design a Global URL Redirection Engine (100K RPS): Replicate mappings globally while ensuring a creator's immediate test click never 404s.
Cassandra (NetworkTopologyStrategy) or DynamoDB Global Tables replicates writes asynchronously across regions in ~1-2s. To prevent a creator from hitting a 404 if they click their new link within 200ms in a different POP, the write response sets a short-lived regional affinity hint (or writes-through to the creator's local L2 Redis) and cold misses fall back cross-region once before returning 404.
Active-Active NoSQL + Cross-Region Fallback
1.First-Char Hint: The slug's first character encodes its origin region, making 1x fallback routing exact.
2.Bounded Fallback: Only fall back for keys passing the Bloom filter or within 10s of creation.
Encoding origin region in the prefix enables exact single-hop fallback during replication lag.
Safe-Browsing Phishing Scanner & Abuse Takedown.
Why this matters: Block malicious destinations at creation time and propagate takedowns globally in seconds.
Think of Safe-Browsing Phishing Scanner & Abuse Takedown as the intuition layer for Design a Global URL Redirection Engine (100K RPS): Block malicious destinations at creation time and propagate takedowns globally in seconds.
On POST /shorten, the Write Worker checks the destination domain/URL against an in-memory Safe-Browsing prefix hash list (<1ms) and rejects known malware/phishing with 400 Bad Request. An async crawler inspects newly created links for redirect chains/phishing kits; confirmed abusers trigger a Redis Pub/Sub cache invalidation across all Edge POPs and mark the DB row BANNED.
Sync Blocklist + Global Cache Purge
1.Fast Takedown: Global Pub/Sub purge evicts malicious L1/L2 cache entries across POPs within 2 seconds.
2.Rate-Limited Writes: Apply strict per-IP/API-key token buckets on POST /shorten to stop spam bots.
Combining sub-millisecond sync blocklists with async deep scanning stops abuse without slowing writes.
Clickstream Kafka + Flink Real-Time Analytics.
Why this matters: Deliver live click counts, geo maps, and bot-filtered unique visitors at 100K RPS.
Think of Clickstream Kafka + Flink Real-Time Analytics as the intuition layer for Design a Global URL Redirection Engine (100K RPS): Deliver live click counts, geo maps, and bot-filtered unique visitors at 100K RPS.
Each Edge POP batches click events asynchronously to regional Kafka clusters (short_clicks). Apache Flink jobs filter known bot User-Agents, enrich IP prefixes with MaxMind GeoIP (dropping raw IPs for GDPR), and compute 1-minute tumbling aggregations + HyperLogLog unique counts into ClickHouse.
Edge-Batched Kafka + Flink Pipeline
1.GDPR Compliance: Strip raw IP addresses inside Flink right after GeoIP lookup.
2.Zero Redirect Impact: Drop analytics buffers gracefully if Kafka backs up; never delay 302s.
Edge-batched Kafka ingestion and Flink enrichment scale analytics to 100K RPS cleanly.
TTL Expiration Engine & Tombstone Compaction.
Why this matters: Support expiring campaign links without degrading Cassandra read performance.
Links with expires_at store the timestamp in the payload and leverage Cassandra/DynamoDB TTLs.
Reading an expired cached entry checks now > expires_at lazily and returns 410 Gone.
Point-Lookup TTL & Tombstone Cleanup
1.Point-Lookup Safety: Partitioning by short_code avoids multi-row tombstone scans.
2.410 Gone: Returning 410 lets Edge CDNs cache the expired state and stop origin hits.
Lazy expiration checks and partition-key point lookups keep TTL cleanup fast and safe.
Practice: Make the trade-off yourself.
How does a Multi-Region URL Shortener generate globally unique short codes without paying 150ms+ cross-continent consensus latency on every write?