Skip to main content
Practice Problems

What is the CAP theorem?

markdown
## Configure Consent Settings Necessary cookies are critical for the core functionalities of the website, and the website will not function properly without them. These cookies do not store any personal data. ### Cookie Types - **_ga_*:** - **_ga:** ### Performance Cookies **[Performance]** ### Advertising Cookies **[Advertising]** ### Uncategorized Cookies **[Uncategorized]** Other uncategorized cookies are those that are being analyzed and have not yet been classified into a category. No cookies to display. ### Consent Options **[Reject]** **[Save my settings]** **[Accept all]** Powered by --- ## Senior System Design Microservices ### CAP Theorem Overview The **CAP Theorem** describes a fundamental trade-off in distributed data storage systems, where data is replicated across multiple nodes. It states that in the presence of a network partition, the system cannot simultaneously guarantee all three properties: **Consistency**, **Availability**, and **Partition tolerance**. ### CAP Properties 1. **Consistency:** Every read request returns the most recent value, meaning all nodes behave as a single source of truth. 2. **Availability:** Every request receives a response; the system is always available and does not become completely blocked. 3. **Partition Tolerance:** The system continues to operate even if communication is lost between parts of the cluster or significant delays occur. ### Practical Implications The practical implication of the theorem is that in a distributed system, network failures are inevitable, so we accept Partition tolerance as a given. Under such conditions, a choice must be made between Partition tolerance + Consistency **(PC)** and Partition tolerance + Availability **(PA)**. ### CP vs. AP - **CP:** The system maintains the correctness and relevance of data but may temporarily block operations to avoid returning conflicting data. Accordingly, the system may sometimes be unavailable and return an error or timeout to preserve data consistency. - **AP:** The system continues to respond at all times but allows for the possibility that during a partition, different nodes may return stale values. In this approach, consistency will occur later, and this approach is also known as Eventual Consistency. ### Conclusion It is important to understand that CAP forces a compromise only when problems arise. In normal operation, the system should have both high availability and acceptable data consistency.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems