How would you design a URL shortener?
Key components: generate short unique IDs (base62 encoding), store mapping in key-value DB, handle redirects with 301/302. Considerations: collision handling, analytics, expiration, custom URLs, rate limiting.
How would you design a news feed (like Twitter/Facebook)?
Fan-out on write: precompute feeds and store in cache for fast reads. Pull model for celebrities. Store posts in timeline DB, use Redis for active feeds. Pagination with cursor-based approach.
How would you design a rate limiter?
Algorithms: token bucket (smooth traffic), leaky bucket (fixed rate), fixed/sliding window. Store counters in Redis with TTL. Distributed: centralized vs per-node. Return 429 status when limited.
How would you design a messaging system (like WhatsApp)?
WebSocket for real-time bidirectional communication. Message queue for offline delivery. Store messages in distributed DB partitioned by conversation. End-to-end encryption. Presence service for online status.
How would you design a video streaming service (like YouTube)?
CDN for content delivery, adaptive bitrate streaming, video transcoding pipeline, chunked uploads, separate storage for metadata and videos. Use object storage. Recommendation engine.
How would you design a web crawler?
URL frontier queue (BFS/DFS), politeness policy (robots.txt, rate limiting), distributed crawling, deduplication (URL fingerprinting), content parsing, storage (document store), periodic recrawling.
How would you design an autocomplete system?
Trie data structure for prefix matching, cache popular queries, precompute suggestions, rank by frequency/recency. Store in memory for speed. Update asynchronously. Handle typos with fuzzy matching.
How would you design a distributed cache?
Consistent hashing for data distribution, replication for availability, eviction policies (LRU), cache invalidation strategy. Handle node failures gracefully. Consider Redis Cluster or Memcached.
How would you design a notification system?
Push notifications (FCM/APNs), email (SES/SendGrid), SMS (Twilio). Message queue for reliability, rate limiting, user preferences, retry logic, deduplication. Track delivery status.
How would you design a file storage system (like Dropbox)?
Block-level deduplication, chunking, metadata store, sync service, conflict resolution, versioning. Use object storage (S3). Delta sync for bandwidth efficiency. Desktop client with local cache.