Practice: Design URL Shortener
Read-heavy distributed URL shortening service with caching, replication, rate limiting, async analytics, and ID generation.
Build this system yourself on the canvas below. Add components, connect them, and run traffic simulations to see where your design holds up and where it breaks.
Functional requirements
- Users can submit a long URL and receive a unique short code (e.g., prism.io/aB3xY) via the URL Shortening Service.
- Visiting a short URL is resolved by the Redirection Service and returns an HTTP 301/302 redirect to the original long URL.
- Users can optionally specify a custom alias; the system guarantees global uniqueness at creation time.
- Short URLs expire after a configurable TTL (default: 1 year); a Cleanup Worker removes expired links, which then return 410 Gone.
- Users can view click analytics (total clicks, referrers, geographic distribution) served from the analytics store.
- Authenticated users can manage (update target, deactivate, delete) their own short URLs via the User Service.
- The system blocks creation of short URLs pointing to known malicious or phishing domains, with CAPTCHA/bot-protection on suspicious flows.
- Bulk short-URL creation is supported via a CSV upload API; an Export Worker produces downloadable CSV exports to object storage.
- QR code generation is available for any short URL on demand.
- Every redirect emits a click event to Kafka, consumed asynchronously by the Analytics Worker; notifications are delivered via a Notification Worker.
Non-functional requirements
- Availability: 99.99% uptime across multiple availability zones and regions; the redirect path keeps serving cached mappings during partial DB or single-zone outages.
- Latency: redirect response under 10 ms at p99 when served from the global Redis cache; under 50 ms on cache miss to a regional replica.
- Scalability: support 10 billion active short URLs and 100,000 redirect requests per second on a stateless, horizontally scalable application layer.
- Throughput: the messaging layer (Kafka) sustains high-throughput click/event fan-out without back-pressuring the redirect path.
- Durability: all URL mappings persisted durably in Cassandra and replicated across at least 3 availability zones; backups and exports stored in object storage (S3/GCS).
- Consistency: eventual consistency acceptable for analytics counters and replicas; strong consistency required for creation uniqueness.
- Performance: 99% of redirect requests served from an in-memory Redis or CDN cache layer (cache-first).
- Security: WAF/DDoS protection at the edge, per-IP and per-user rate limiting, input validation and blocklist checks, plus CAPTCHA/bot protection on creation.
- Geo-distribution: Geo-DNS plus CDN edge nodes and multi-region read replicas serve redirects with minimal RTT worldwide.
- Observability: real-time metrics, logs, and traces (Prometheus, ELK/OpenSearch, Jaeger) with Grafana dashboards and Alertmanager p99 alerting within 30 seconds.