System design interview questions for senior roles. Covers scalability, databases, caching, load balancing, and distributed systems.
5 Questions Detailed Answers
1How would you design a URL shortener (like bit.ly)?
Medium
View Answer
Components: (1) API: POST /shorten, GET /:shortId. (2) ID generation: Base62 encoding of auto-increment ID or random 7-char string. (3) Storage: NoSQL (DynamoDB) for key-value lookups. (4) Cache: Redis for popular URLs. (5) Analytics: async event logging. Scale: 100M URLs → ~500GB. Read-heavy → cache aggressively.
2Explain CAP theorem.
Hard
View Answer
In a distributed system, you can only guarantee 2 of 3: Consistency (all nodes see same data), Availability (every request gets a response), Partition tolerance (system works despite network failures). Since partitions are inevitable, choose CP (banking) or AP (social media). Examples: MongoDB = CP, Cassandra = AP.
3What is database sharding?
Hard
View Answer
Sharding splits data across multiple databases. Strategies: (1) Range-based: shard by date/ID range, (2) Hash-based: hash(key) % num_shards, (3) Directory-based: lookup table. Challenges: cross-shard queries, rebalancing, joins. Use when vertical scaling hits limits (typically 1TB+).
4How does a load balancer work?
Medium
View Answer
Load balancers distribute traffic across servers. Algorithms: Round Robin, Least Connections, IP Hash, Weighted. Types: L4 (TCP/UDP — faster) vs L7 (HTTP — smarter routing). Tools: Nginx, HAProxy, AWS ALB. Health checks remove unhealthy servers. Session stickiness for stateful apps.
5Design a notification system.
Hard
View Answer
Components: (1) Notification Service accepts requests via API/events, (2) Priority Queue for ordering, (3) Rate Limiter to prevent spam, (4) Channel adapters (email/SMS/push), (5) Template engine for messages, (6) Analytics for delivery tracking. Scale: async processing with message queues (Kafka/SQS). Store preferences in NoSQL.