rule

CAP
Theorem

The physics of distributed systems. Eric Brewer's fundamental law that dictates what you must sacrifice when the network fails.

Defining C, A, and P

Consistency (C)

Every read receives the most recent write or an error. All nodes see the same data at the same time.

Availability (A)

Every request receives a (non-error) response, without the guarantee that it contains the most recent write.

Partition Tolerance (P)

The system continues to operate despite an arbitrary number of messages being dropped by the network.

Why Partition Tolerance is Mandatory

In a real-world network, partitions (failures) **will** happen. Cables get cut, routers reboot, and switches fail.

P is NOT A CHOICE.

"If you lose Partition Tolerance, your system isn't distributed—it's just a single server."

Pick Two: CP vs AP

CP: Consistency + Partition

When a partition occurs, the system stops accepting writes to Ensure data integrity. It chooses **Reliability over Availability**.

Ex: MongoDB (Default), HBase, Redis (Single Node).

AP: Availability + Partition

The system continues to accept writes on all nodes. Data may be inconsistent, but the system is **Always Available**.

Ex: Cassandra, DynamoDB, CouchDB.

The CA Lie

You often see "CA" (Consistency + Availability) systems mentioned. In a distributed environment, **CA does not exist**.

A CA system requires 0 network failures. Since that is physically impossible in a network of more than 1 machine, you cannot build a CA distributed system.

Beyond CAP: PACELC

CAP only tells us what happens during a **Partition (P)**. What about when things are working fine?

"If there is a Partition (P), choose (A) or (C)..."

"Else (E), choose Latency (L) or Consistency (C)."

"PACELC is the real-world extension of CAP, governing almost all modern DB trade-offs."