Skip to main contentSkip to user menuSkip to navigation

Design a URL Shortener (TinyURL/bit.ly)

Design a scalable URL shortening service handling 100M daily URL creations and 10B daily redirects with sub-100ms latency and 99.9% availability.

High ThroughputCachingURL Generation

1.1 Clarifying Questions & Requirements

Q: What's the expected scale and performance requirements?
A: Handle 100M URL shortens per day, 10B redirects per day. 100:1 read:write ratio. Redirect latency must be under 100ms for good user experience.
Engineering Implications: This massive scale requires horizontal scaling, aggressive caching, and geographic distribution. The 100:1 ratio means read-optimized architecture with cache-heavy design.
Q: What features beyond basic shortening are needed?
A: Custom aliases (vanity URLs), expiration dates, analytics and click tracking, bulk URL creation API, user accounts, and branded domains for enterprise customers.
Engineering Implications: Custom aliases require collision detection and reservation systems. Analytics need real-time streaming architecture to avoid impacting redirect performance. Enterprise features require multi-tenancy.
Q: What are the availability and consistency requirements?
A: 99.9% availability is required. Eventual consistency is acceptable for analytics, but URL mappings must be strongly consistent to avoid broken redirects.
Engineering Implications: Strong consistency for URL creation prevents duplicate short codes. Read replicas can serve redirects with slight delay. Analytics can use eventual consistency for better performance.
Q: How should we handle security and abuse prevention?
A: Prevent spam and malicious URLs. Rate limiting per user/IP. Content filtering for adult/malicious sites. HTTPS enforcement. No predictable URL patterns to prevent enumeration.
Engineering Implications: Requires real-time URL reputation checking, machine learning for spam detection, rate limiting with sliding windows, and non-sequential short code generation.
Q: What about compliance and data requirements?
A: GDPR compliance for user data, data retention policies (delete after 5 years unused), audit trails for enterprise, geographic data residency requirements.
Engineering Implications: Need data anonymization for analytics, user data export/deletion capabilities, and regional database deployment for data sovereignty compliance.

1.2 Back-of-the-Envelope Calculations

Traffic & Request Volume

URL creations100M/day
= 1,157/sec average, 3,000/sec peak
Redirects10B/day
= 115,740/sec avg, 300K/sec peak
Total QPS300K QPS peak
Redirect-heavy workload, 100:1 ratio
Analytics writes10B events/day
One event per redirect for tracking

Storage Requirements

URL record size500 bytes avg
Short code + long URL + metadata
Daily storage50GB/day
100M URLs × 500 bytes
5-year storage91TB total
With 20% growth YoY
Analytics data200TB/year
Click events with full context

Infrastructure Estimates

Web servers150 instances
2K QPS each = 300K total capacity
Database shards20 shards
MySQL, 5TB each with replication
Cache layer5TB Redis
80% cache hit rate for redirects
Analytics pipelineKafka + ClickHouse
Real-time event processing

Monthly Operating Costs

Compute (web/app)$45K/month
150 instances × $300/month
Database cluster$60K/month
20 shards × $3K/month
Cache infrastructure$15K/month
5TB Redis cluster
Total infrastructure$120K/month
Including networking, monitoring
No quiz questions available
Quiz ID "url-shortener" not found

Interview Practice Questions

Practice these open-ended questions to prepare for system design interviews. Think through each scenario and discuss trade-offs.

1

Global Scale URL Shortener: Design a URL shortener supporting 100B URLs with global distribution across 15 regions. Address unique ID generation, cross-region replication, cache consistency, and 99.99% availability requirements.

2

Analytics & Business Intelligence: Build a comprehensive analytics system for URL shortener that tracks clicks, geography, devices, referrers with real-time dashboards. Handle 1B+ daily events with sub-second query latency for business metrics.

3

Security & Content Moderation: Implement URL safety checking, malware detection, phishing prevention, and abuse protection. Address real-time threat detection, content analysis, user reporting, and automated moderation workflows.

4

Enterprise Features: Design enterprise-grade URL shortener with custom domains, branded links, team management, SSO integration, advanced analytics, and white-label solutions. Address multi-tenancy, billing, and enterprise security requirements.

5

Mobile SDK & API Platform: Build mobile SDKs and API platform for URL shortener with offline support, conflict resolution, rate limiting, authentication, and developer tools. Address SDK performance, API versioning, and developer experience.

6

Machine Learning Integration: Integrate ML for click prediction, fraud detection, optimal expiration, and personalized analytics. Address feature engineering, model serving, A/B testing, and real-time inference at scale.