Skip to main content

CAP Theorem

The CAP theorem is a fundamental principle in distributed computing that highlights the trade-offs involved in designing systems that can operate across multiple machines or nodes. It states that a distributed system can only guarantee two of the following three properties:   

  1. Consistency: All nodes in the system have the same, up-to-date data at all times.
  2. Availability: The system is always operational and accessible for read and write operations.
  3. Partition Tolerance: The system continues to operate correctly even in the presence of network failures or partitions.

Why is the CAP Theorem Important?

  • Trade-offs: It forces system designers to make conscious decisions about which properties are most critical for their specific application.   
  • Real-world limitations: It highlights the inherent limitations of distributed systems and the challenges involved in achieving high availability and consistency in the face of network failures.   

Understanding the Trade-offs

  • CP (Consistency and Partition Tolerance): Systems that prioritize consistency and partition tolerance often sacrifice availability. In case of a network partition, they may temporarily become unavailable to ensure data integrity.   
  • AP (Availability and Partition Tolerance): Systems that prioritize availability and partition tolerance may sacrifice strong consistency. They can continue to operate even during network failures, but data may not be immediately consistent across all nodes.   
  • CA (Consistency and Availability): Systems that prioritize consistency and availability cannot tolerate network partitions. If a partition occurs, the system must either become unavailable or sacrifice consistency.

Visualizing the CAP Theorem

Image of CAP theorem triangle

Real-world Examples

  • Amazon Dynamo: A highly available key-value store that prioritizes AP.   
  • Google Spanner: A globally distributed database that prioritizes CP.

In Conclusion

The CAP theorem is a fundamental concept in distributed systems that helps designers understand the trade-offs involved in building reliable and scalable systems. By carefully considering the specific requirements of their applications, designers can choose the appropriate trade-offs and design systems that meet their needs.

Comments

Popular posts from this blog

System Design Roadmap Learning

🗓️ Phase 1: Fundamentals of System Design (Week 1–2) Introduction to System Design What is System Design? : Process of defining architecture, components, modules, and interfaces of a system. High-Level Design (HLD) vs. Low-Level Design (LLD) : HLD focuses on system architecture, components, and data flow; LLD deals with classes, modules, methods. Interview expectations : Focus on scalability, availability, consistency, bottlenecks, trade-offs, and component interactions. Networking Basics IP, DNS, Load Balancer : Understand how routing works, domain resolution, and request distribution. HTTP vs. HTTPS : Protocols for communication; HTTPS adds encryption (TLS). TCP vs. UDP : TCP is reliable and connection-oriented; UDP is faster, connectionless. WebSockets & Long Polling : For real-time bidirectional communication. Databases SQL vs. NoSQL : Structured vs. unstructured; relational vs. document/graph. ER modeling : For relational database schema design. CAP Theorem : Trade-off betwee...