1. Design a URL Shortening Service like bit.ly
Answer:
- Use a unique ID (auto-increment or UUID) converted to base62 for short keys.
- Store mappings (short_key → long_url) in a scalable DB (NoSQL like DynamoDB or SQL).
- Use caching (Redis) for fast redirects.
- Handle collisions and custom URLs by checking DB uniqueness.
- Scale with load balancers, sharding, and replication.
- Provide analytics by tracking click counts asynchronously.
2. Design a Social Media Feed
Answer:
- Store posts, users, and followers in DB.
- Use fan-out-on-write for small user base or fan-out-on-read for large scale.
- Cache feeds for fast access.
- Use a ranking algorithm to order posts by relevance/time.
- Use message queues to update feeds asynchronously.
3. Design a Messaging Service like WhatsApp
Answer:
- Use persistent queues for message delivery.
- Implement end-to-end encryption.
- Use presence services to show online status.
- Support offline message storage.
- Use push notifications for message alerts.
4. Design an Online Bookstore
Answer:
- Catalog service with metadata on books.
- Search service with indexing (Elasticsearch).
- User accounts, orders, and payment processing modules.
- Recommendation engine for personalized suggestions.
- Use CDN for serving images.
5. Design a File Storage Service
Answer:
- Chunk files and store in distributed storage.
- Use metadata service to track file info and versions.
- Replicate chunks for durability.
- Support file upload, download, and sharing.
- Handle consistency with eventual or strong consistency models.
6. Design a Ride-Sharing Service
Answer:
- Real-time location tracking with GPS.
- Matching engine pairs riders with drivers.
- Surge pricing based on demand.
- Notification service to alert users.
- Payment and rating services.
7. Design a Web Crawler
Answer:
- URL frontier to manage URLs to crawl.
- Fetcher workers to download pages.
- Parser to extract URLs and content.
- Deduplication to avoid repeated crawling.
- Indexer to store and search content.
8. Design a Video Streaming Service
Answer:
- Use CDN for content delivery.
- Adaptive bitrate streaming for various devices.
- Storage service for video files.
- Transcoding pipeline to convert videos.
- Player with buffering and playback control.
9. Design a Cache System
Answer:
- Use LRU or LFU eviction policies.
- Distributed cache with consistent hashing.
- Cache invalidation strategies (write-through, write-back).
- Support for replication and failover.
10. Design a Real-Time Chat Application
Answer:
Offline message support.
Use WebSockets or similar protocols for real-time messaging.
Message queues for delivery guarantees.
Persistent storage for message history.
Presence detection and typing indicators.