System Design: Production-Ready URL Shortening Service
Goal
Design a production-ready URL shortening service that can issue short links, resolve them at low latency, and provide management and analytics. The service must be scalable, reliable, and secure.
Requirements
-
Public APIs to:
-
Create short links (optionally with custom alias and expiration/TTL).
-
Resolve short links to their destination.
-
Manage short links (enable/disable, update destination, extend TTL, fetch stats).
-
Propose a database schema for links and analytics.
-
Propose an ID/token generation strategy with collision avoidance.
-
Describe read/write paths with caching.
-
Discuss partitioning, replication, and consistency choices.
-
Include rate limiting, abuse/spam mitigation.
-
Include analytics and click tracking.
-
Describe TTL handling and cleanup.
-
Strategies for high availability (HA), disaster recovery (DR), and monitoring.
-
Compare key trade-offs under different traffic patterns (read-heavy vs write-heavy, hot-spot links vs long-tail, single-region vs global).
Assume a consumer-facing scale with very high read QPS and moderate writes, and that links can be public or managed by authenticated users.