Skip to content
CAP Theorem — Explained with Examples

CAP Theorem — Explained with Examples

DodaTech Updated Jun 15, 2026 2 min read

CAP Theorem states that a distributed data system can guarantee at most two of three properties: Consistency, Availability, and Partition Tolerance.

CAP Theorem, also called Brewer’s Theorem (proposed by Eric Brewer in 2000), formalizes the trade-offs in distributed systems. The three properties are:

Consistency (C) — Every read receives the most recent write or an error.

Availability (A) — Every request receives a (non-error) response, without guarantee it contains the latest write.

Partition Tolerance (P) — The system continues operating despite network partitions between nodes.

Why CAP Matters

Network partitions are unavoidable in distributed systems. The theorem forces architects to choose: when a network split happens, do you serve stale data (sacrifice C) or refuse to serve (sacrifice A)? Different databases make different trade-offs.

Real-World Analogy

Two friends with walkie-talkies: if the signal drops (partition), you can either repeat yourself until confirmed (Consistency, but no Availability) or keep talking and hope they heard (Availability, but no Consistency). You can’t do both during a signal loss.

Example: CAP Trade-offs

# CP system (Consistency + Partition Tolerance)
# — sacrifices availability during partitions
class CPSystem:
    def __init__(self):
        self.nodes = {}
        self.locked = False

    def write(self, key, value):
        if self.locked:
            raise Exception("System unavailable — partition detected")
        self.nodes[key] = value

# AP system (Availability + Partition Tolerance)
# — sacrifices consistency during partitions
class APSystem:
    def __init__(self):
        self.nodes = {}

    def write(self, key, value):
        self.nodes[key] = value

# Banking → CP (consistency critical)
# Social media → AP (availability critical)

Related Terms

ACID, BASE, Replication, Partitioning

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro