đź§  What is the CAP Theorem?

The CAP Theorem, proposed by Eric Brewer, states that a distributed system can only guarantee two out of the following three properties at the same time:

LetterStands forMeans…
CConsistencyEvery read receives the most recent write or an error
AAvailabilityEvery request receives a non-error response, even if it’s not the latest
PPartition ToleranceThe system continues to operate even if network failures (partitions) occur

🧪 Let’s Break Each One Down

âś… 1. Consistency

• All nodes see the same data at the same time.

• If you write something, and then read it immediately, you get the updated value.

Like in a relational database with ACID transactions.


âś… 2. Availability

• The system always responds to requests, even if it’s not 100% up-to-date.

• Reads/writes will not fail (though they might return older data).

Think of it like: “The show must go on”, even during problems.


âś… 3. Partition Tolerance

• The system can keep running even if network links between nodes fail (i.e., communication between parts of the system is broken).

This is non-negotiable in real distributed systems — partitions will happen.


⚠️ The Trade-off

In the presence of a network partition (P), a system can choose either Consistency (C) or Availability (A) — not both.

So you get one of the following:

TypeGuaranteesCompromisesExample DBs
CPConsistency + Partition ToleranceMight reject requestsHBase, MongoDB (strong mode), PostgresSQL, Spanner
APAvailability + Partition ToleranceMight return stale dataCouchDB, Cassandra, DynamoDB
CA (not possible if partitioned)Consistency + Availability (in perfect networks only)Not partition-tolerantTraditional single-node RDBMS

📌 Real-World Examples

ScenarioWhat’s sacrificed?Why?
A global chat app always shows old messages during network lag❌ ConsistencyPrioritizes availability
A bank refuses your transaction if it can’t talk to the central server❌ AvailabilityPrioritizes consistency
A relational DB on one server (no partition)❌ Partition ToleranceWorks well locally, not in distributed systems

📝 Summary

In a network partition, a distributed system must choose between: • Consistency (C): Return accurate, up-to-date data — even if it means denying service • Availability (A): Always respond — even if the data is stale or inconsistent And it must tolerate partitions (P) because networks are inherently unreliable.