Design a Scalable URL Shortening Platform
Context
Build a Bitly-like URL shortener that maps long URLs to short codes and performs HTTP redirection reliably at global scale. Assume the service is read-heavy, stores billions of links, and must meet low latency and high availability requirements.
Requirements
-
APIs
-
Define REST APIs for:
-
Create short link (with optional custom alias and TTL)
-
Expand short code to original URL (preview)
-
Delete/disable a short link
-
Short Code Generation
-
Strategy: hashing and/or counter-based IDs
-
Base-N encoding (e.g., base62)
-
Collision handling
-
Support custom aliases
-
TTL/expiration behavior
-
Data Model and Storage
-
Schema for links, users, and analytics
-
Storage for billions of links (trade-offs: SQL vs NoSQL, KV stores)
-
Indexing and sharding strategy
-
Read-Heavy Architecture
-
Caches (edge and regional)
-
CDN and edge compute considerations
-
Redirect behavior (301/302/307) and caching semantics
-
Rate Limiting and Abuse Prevention
-
Per-IP/account rate limiting
-
Malware/phishing detection, Safe Browsing integration
-
Blacklist/allowlist, link scanning
-
Analytics
-
Click counts, uniques, geo, time-of-day
-
Real-time vs batch pipelines
-
GDPR/Compliance
-
Data minimization, retention, encryption
-
Right-to-be-forgotten, data residency
-
Capacity Plan
-
QPS estimates (create vs redirect)
-
Storage sizing (links and logs)
-
Fault-Tolerant Deployment
-
Multi-AZ/region replication
-
Sharding, failover
-
Consistency Trade-offs
-
Strong vs eventual consistency (creation, expansion, deletion)
-
Global uniqueness of custom aliases