Walk me through how you would design a URL shortener service like bit.ly that handles 100 million URLs per day.
Why interviewers ask this
Tests system design skills, scalability understanding, and ability to break down complex problems into manageable components. Evaluates knowledge of distributed systems, database design, and performance optimization.
Sample Answer
I'd start with a high-level architecture: load balancers, application servers, databases, and caching layers. For URL encoding, I'd use base62 encoding with a counter or hash approach to generate unique short codes. The database would store mappings between short codes and original URLs, partitioned by hash of the short code for horizontal scaling. I'd implement Redis caching for frequently accessed URLs to reduce database load. For 100M URLs daily, that's about 1,200 requests per second, so I'd need multiple application servers behind load balancers. I'd also add analytics tracking, rate limiting to prevent abuse, and CDN for global performance. Key considerations include handling duplicate URLs, expiration policies, and monitoring for popular links that might cause hot spots.
Pro Tips
Start with basic requirements then scale up, discuss trade-offs between different encoding approaches, mention specific technologies like Redis and partitioning strategies
Avoid These Mistakes
Jumping into implementation details without clarifying requirements, ignoring scalability concerns, not discussing data consistency or caching strategies