· Glossary  · 2 min read

What Is the CAP Theorem?

The CAP Theorem is the law that explains why distributed systems can only provide two of three guarantees: Consistency, Availability, Partition Tolerance.

The CAP Theorem is the law that explains why distributed systems can only provide two of three guarantees: Consistency, Availability, Partition Tolerance.

In distributed systems physics limits what you can do. You cannot have everything.

The CAP Theorem is the law that explains why.

Simple Definition

The CAP Theorem states that a distributed data store can only provide two of the following three guarantees simultaneously:

  • Consistency (C): Every read receives the most recent write or an error. (Everyone sees the same data).
  • Availability (A): Every request receives a (non-error) response without the guarantee that it contains the most recent write. (The system stays up).
  • Partition Tolerance (P): The system continues to operate despite an arbitrary number of messages being dropped or delayed by the network between nodes. (The network breaks but the system survives).

Consistency, Availability, Partition Tolerance. Pick two.

Because networks are unreliable Partition Tolerance is mandatory. You cannot choose to have a perfect network.

So the real choice is: CP or AP?

  • CP (Consistency + Partition Tolerance): If the network breaks we refuse requests to ensure data is correct. (Bank ATM).
  • AP (Availability + Partition Tolerance): If the network breaks we accept requests even if the data might be stale. (Social Media Feed).

The Trade-off

This trade-off defines your database choice.

SQL databases (like Postgres) usually default to Consistency. They prioritize correctness. NoSQL databases (like Cassandra) usually default to Availability. They prioritize uptime.

Visualizing CAP

How do you show this constraint?

Distributed nodes and network breaks

In a System Architecture Diagram you draw multiple database nodes in different regions.

You draw a lightning bolt across the connection line between Region A and Region B. This represents the “Network Partition.”

You then annotate the behavior. “In this state Region A accepts writes but Region B is read-only.” This visualizes your strategy for handling the inevitable failure.

To understand distributed logic you need these terms:

  • Eventual Consistency: The model used in AP systems where data becomes consistent over time. Read more about Eventual Consistency.
  • Distributed System: A group of computers working together as a unified system.
  • Replication: The process of synchronizing data across multiple nodes.

For more on visualizing distributed trade-offs check out our System Design Guide.

Back to Blog

Related Posts

View All Posts »