Blog Image

System Design Interview Prep


Q1. What is the CAP theorem?

๐Ÿ”น Question Restated Explain the CAP theorem in distributed systems and its impact on design.

1. Simple metaphor Imagine a bank with 3 branches:

  • Consistency = all branches show same balance instantly.
  • Availability = customers can always withdraw.
  • Partition tolerance = even if one branch loses network, system still works.

You canโ€™t guarantee all three perfectly at once.

2. Deep dive theory

  • CAP theorem: In a distributed system, you can only choose two of:

    • Consistency (every node sees same data at same time).
    • Availability (system responds even during failure).
    • Partition tolerance (works despite network splits).
  • Trade-offs:

    • CP (Consistency + Partition) โ†’ e.g., Zookeeper.
    • AP (Availability + Partition) โ†’ e.g., DynamoDB, Cassandra.

Q2. What is scalability?

๐Ÿ”น Question Restated How do you define and achieve scalability in system design?

1. Simple metaphor A restaurant with long queues can either:

  • Add bigger tables (vertical scaling).
  • Add more branches (horizontal scaling).

2. Deep dive theory

  • Vertical scaling: add more CPU, memory.
  • Horizontal scaling: add more servers/nodes.
  • Scalability bottlenecks: DB, caching, network.

Q3. What is load balancing and why is it important?

๐Ÿ”น Question Restated Explain load balancing and its role in distributed systems.

1. Simple metaphor Think of a traffic cop at an intersection directing cars evenly across multiple roads.

2. Deep dive theory

  • Load balancer distributes incoming traffic across servers.

  • Benefits:

    • Prevents overload.
    • Enables horizontal scaling.
    • Provides failover.
    • Algorithms: Round-robin, least connections, weighted routing.

Q4. What is caching and why is it important?

๐Ÿ”น Question Restated Why do systems use caching, and what are the strategies?

1. Simple metaphor Instead of asking the chef to cook from scratch every time, keep popular dishes pre-made near the counter.

2. Deep dive theory

  • Caching = storing frequently accessed data in faster storage.

  • Types:

    • Client-side (browser cache).
    • CDN (Cloudflare, Akamai).
    • Server-side (Redis, Memcached).
    • Eviction policies: LRU, LFU, TTL.