CAP Theorem in System Design (original) (raw)

Last Updated : 30 Apr, 2026

According to the CAP theorem, only two of the three desirable characteristics consistency, availability, and partition tolerance can be shared or present in a networked shared-data system or distributed system.

Copy-of-devops_20

CAP Theorem

Properties

The property of three distributed system characteristics to which CAP Theorem refers:

devops_21

Properties of CAP Theorem

1. Consistency

Consistency defines that all clients see the same data simultaneously, no matter which node they connect to in a distributed system. For eventual consistency, the guarantees are a bit loose. Eventual consistency guarantee means client will eventually see the same data on all the nodes at some point of time in the future.

devops_22

Consistency

**In the above Diagram

2. Availability

Availability defines that all non-failing nodes in a distributed system return a response for all read and write requests in a bounded amount of time, even if one or more other nodes are down.

devops_23

Availability

**In above Diagram

3. Partition Tolerance

Partition Tolerance defines that the system continues to operate despite arbitrary message loss or failure in parts of the system. Distributed systems guaranteeing partition tolerance can gracefully recover from partitions once the partition heals.

devops_24

Partition Tolerance

**In the above Diagram

Trade-Offs in the CAP Theorem

The CAP Theorem states that a distributed system can provide only two out of three guarantees at the same time: Consistency (C), Availability (A), and Partition Tolerance (P). When a network partition occurs, a system must choose between maintaining consistency or availability.

We can classify the systems into the following three categories:

devops_26

Trade-offs in CAP theorem

1. CA System

A CA system provides Consistency and Availability but does not tolerate network partitions. This means that all nodes always return the same data and the system remains accessible, but if a network partition occurs, the system cannot continue operating correctly.

**Example: Traditional relational databases in a single data center are often designed as CA systems.

2. CP System

A CP system provides Consistency and Partition Tolerance but sacrifices availability during network failures. When a partition occurs between nodes, the system may temporarily block requests to ensure that all nodes maintain consistent data.

Systems that prefer consistency over availability during partitions.
**Examples: MongoDB (default replica set behavior), HBase

3. AP System

An AP system provides Availability and Partition Tolerance but does not guarantee immediate consistency. During a network partition, the system continues to serve requests, but some nodes may return stale or outdated data until the system eventually synchronizes.

Systems that prefer availability and may return eventually consistent data.
**Examples: Apache Cassandra, DynamoDB

Example

This example demonstrates how the CAP theorem trade-off works during a network partition in a distributed system.

devops_25

Example

**In the above Diagram,

Use Cases

Here we will see how we can use all the trade-off system in real application:

1. Banking Transactions (CP System)

**Problem Statement

Imagine a bank teller updating your account balance on a secure computer system. This system prioritizes consistency (C) and partition tolerance (P).

**We use CP System

**Problem Statement

Think of your newsfeed on a social media platform constantly updating with new posts and stories. This system prioritizes availability (A) and partition tolerance (P).

**We use AP System

3. Online Shopping Cart (Hybrid System CAP System):

**Problem Statement

Imagine an online shopping cart, adding items, and checking out. This system might employ a hybrid approach balancing CAP trade-offs.

**We use AP and CP System