Interview
System Design Fundamentals — Interview Questions (80+)
Detailed Questions
1. How do you approach a system design interview?
- Short: Clarify → estimate → high-level → deep-dive → bottlenecks → trade-offs.
- Detailed: (1) Clarify functional + non-functional requirements (scale, latency, consistency). (2) Back-of-envelope estimates (QPS, storage, bandwidth). (3) Draw a high-level architecture (clients, API, services, DB, cache, queue). (4) Deep-dive a component. (5) Identify bottlenecks and scale them. (6) Discuss trade-offs and failure modes.
- Example: Design a URL shortener: hashing, DB schema, cache, redirect path.
2. Vertical vs horizontal scaling?
- Short: Bigger machine vs more machines.
- Detailed: Vertical (scale-up) is simple but bounded and a single point of failure. Horizontal (scale-out) adds nodes behind a load balancer—needs statelessness, partitioning, and coordination but scales further and improves availability.
- Example: Add app servers behind an LB; shard the DB.
3. Explain the CAP theorem.
- Short: Under a partition, choose Consistency or Availability.
- Detailed: A distributed store can't simultaneously guarantee Consistency, Availability, and Partition tolerance. Partitions happen, so you trade C vs A. CP systems reject some requests to stay consistent; AP systems stay available but may serve stale data (eventual consistency).
- Example: ZooKeeper (CP) vs Dynamo/Cassandra (AP).
4. What is consistent hashing and why use it?
- Short: Maps keys/nodes on a ring to minimize remapping on changes.
- Detailed: With plain modulo hashing, adding/removing a node remaps most keys. Consistent hashing places nodes and keys on a ring; only keys between the changed node and its predecessor move. Virtual nodes balance load.
- Example: Distributed caches/sharded stores.
5. Caching strategies?
- Short: Cache-aside, read-through, write-through, write-back.
- Detailed: Cache-aside: app loads on miss and populates. Read-through: cache loads from DB. Write-through: write to cache+DB synchronously. Write-back: write to cache, async to DB (fast, risk of loss). Use TTLs and eviction (LRU/LFU). Beware stampede and stale data.
- Example: Redis cache-aside in front of a SQL DB.
6. SQL vs NoSQL?
- Short: Relational/ACID vs flexible/scalable/eventually-consistent.
- Detailed: SQL: strong schema, joins, ACID transactions, vertical scaling, great for complex queries/integrity. NoSQL: key-value/document/column/graph, horizontal scaling, flexible schema, often eventual consistency—great for scale and simple access patterns.
- Example: Orders/payments → SQL; session store/feed → NoSQL.
7. How do message queues help?
- Short: Decouple producers/consumers, smooth load, enable async.
- Detailed: Queues (Kafka, RabbitMQ, SQS) buffer work, provide backpressure, retries, and durability, and let services scale independently. Choose at-least-once vs exactly-once semantics; design idempotent consumers.
- Example: Order service publishes events; email/inventory consume them.
8. How do you design for reliability/availability?
- Short: Redundancy, failover, retries, timeouts, circuit breakers.
- Detailed: Eliminate single points of failure (multi-AZ/region), health checks + automatic failover, retries with exponential backoff + jitter, timeouts, bulkheads, circuit breakers, and graceful degradation.
- Example: Replica DB promoted on primary failure.
9. Database scaling techniques?
- Short: Replication, partitioning/sharding, indexing, caching.
- Detailed: Read replicas scale reads; sharding splits data across nodes by a key (hash/range/geo). Add indexes for query speed (cost on writes). Cache hot reads. Use CDC for derived stores.
- Example: Shard users by user_id hash; replicas for analytics.
10. Idempotency and why it matters?
- Short: Same request applied once even if retried.
- Detailed: Network retries can duplicate requests; idempotency keys/dedup ensure exactly-once effects (e.g., don't charge twice). Use unique request IDs and upserts.
- Example: Payment with an idempotency key.
Rapid-Fire (Q → A)
- Latency vs throughput? → Time per op vs ops per second.
- Availability target? → e.g. 99.9% ("three nines").
- 99.99% downtime/year? → ~52 minutes.
- SLA vs SLO vs SLI? → Agreement vs objective vs indicator.
- Load balancer role? → Distribute traffic.
- LB algorithms? → Round-robin, least-conn, hashing.
- L4 vs L7 LB? → Transport vs application layer.
- Reverse proxy? → Fronting server (nginx).
- CDN purpose? → Cache static content near users.
- Stateless service benefit? → Easy horizontal scaling.
- Sticky sessions downside? → Hurts scaling/failover.
- Session store? → Redis/DB for shared state.
- Sharding? → Partition data across nodes.
- Shard key choice? → Even distribution, avoid hotspots.
- Replication? → Copies for reads/HA.
- Leader-follower? → Writes to leader, reads from followers.
- Replication lag? → Stale reads on followers.
- Quorum? → Majority for read/write consistency.
- CAP under partition? → Pick C or A.
- PACELC? → Else latency vs consistency.
- ACID? → Atomicity, Consistency, Isolation, Durability.
- BASE? → Basically Available, Soft state, Eventual.
- Eventual consistency? → Converges over time.
- Strong consistency? → Reads see latest write.
- Read-your-writes? → See your own updates.
- Optimistic concurrency? → Version check on write.
- Pessimistic locking? → Lock before update.
- Index trade-off? → Faster reads, slower writes.
- B-tree index? → Range queries.
- Hash index? → Equality lookups.
- Denormalization? → Duplicate for read speed.
- Normalization? → Reduce redundancy.
- OLTP vs OLAP? → Transactions vs analytics.
- Data warehouse? → Analytics store.
- Cache eviction? → LRU/LFU/TTL.
- Cache stampede fix? → Locking/request coalescing.
- Write-through? → Sync cache+DB.
- Write-back? → Async to DB.
- Cache-aside? → App manages cache.
- CDN cache invalidation? → Hard problem; versioned URLs.
- Message queue benefit? → Decoupling/async.
- Pub/sub? → Fan-out to subscribers.
- At-least-once? → May duplicate.
- At-most-once? → May drop.
- Exactly-once? → Hard; idempotency + dedup.
- Kafka core concept? → Partitioned log.
- Backpressure? → Slow consumer signals producer.
- Dead-letter queue? → Failed messages.
- Idempotency key? → Dedup requests.
- Rate limiting? → Throttle requests.
- Token bucket? → Allow bursts up to capacity.
- Leaky bucket? → Smooth constant rate.
- Circuit breaker? → Stop calling failing service.
- Bulkhead? → Isolate failures.
- Timeout importance? → Avoid hanging.
- Retry with backoff? → Exponential + jitter.
- Thundering herd? → Synchronized retries overload.
- Health check? → Liveness/readiness.
- Graceful degradation? → Reduced functionality on failure.
- Blue-green deploy? → Two environments switch.
- Canary deploy? → Gradual rollout.
- Feature flag? → Toggle features.
- Microservices benefit? → Independent deploy/scale.
- Microservices cost? → Distributed complexity.
- Monolith benefit? → Simplicity.
- API gateway? → Single entry, routing/auth.
- Service discovery? → Locate service instances.
- Saga pattern? → Distributed transactions via steps.
- 2PC? → Two-phase commit (blocking).
- Outbox pattern? → Reliable event publishing.
- CQRS? → Separate read/write models.
- Event sourcing? → Store events as truth.
- CDC? → Change Data Capture.
- Hot partition? → Skewed load.
- Geo-replication? → Multi-region copies.
- Multi-region active-active? → All regions serve writes.
- Data locality? → Keep data near compute.
- Estimating QPS? → Users × actions / time.
- Estimating storage? → Records × size × retention.
- Designing for 10x growth? → Stateless, shard, cache, queue.
- Observability pillars? → Logs, metrics, traces.
- Golden rule? → Start simple; scale the proven bottleneck; justify trade-offs.