Data Modeling Updated: 2026-04-03

What is CAP Theorem?

A theorem stating that a distributed data store can only guarantee two of the three: Consistency, Availability, and Partition Tolerance.

From the field

CAP theorem is the 2000 formalization by Eric Brewer of a truth every distributed-systems engineer learns the hard way: when the network partitions (and it will), you can't have both strict consistency and full availability. You have to choose. Every distributed database you use has made this choice explicitly, sometimes surprisingly, and often configurably.

What "choosing CP vs AP" actually looks like

CP databases refuse writes during a partition rather than risk divergence. MongoDB (primary-secondary with majority write concern), HBase, Redis Cluster, etcd, ZooKeeper — all of these will return errors to clients when enough replicas are unreachable. Operationally: queries fail loudly during network issues, but the data you get back is always correct. AP databases accept writes on any available node and reconcile later. Cassandra, DynamoDB, Riak, CouchDB — these keep taking writes during partitions, at the cost of potentially returning stale or divergent data that gets resolved via vector clocks or last-write-wins. Pick based on what your workload tolerates: a fraud-detection system wants CP (wrong answer is worse than no answer); a shopping cart wants AP (better to accept an order and reconcile than to reject during an S3 hiccup).

Field story

A fintech client ran their transaction ledger on Cassandra and spent two years fighting consistency anomalies ("why did this transaction appear twice?"). The root cause was always some combination of tuned-too-low consistency levels (QUORUM where they needed ALL), hinted-handoff replaying duplicates, and developers assuming read-your-writes guarantees Cassandra doesn't give you out-of-the-box. Moving the ledger to a CP store (CockroachDB) fixed the class of bugs entirely. Cassandra was the wrong choice for that workload; they'd picked it for "scalability" without understanding the CAP tradeoff. Lesson: CAP isn't an abstract theorem, it's an operational constraint. Read your database's documentation on what happens during a partition before building on it.

The CAP Theorem (also known as Brewer's Theorem) states that any distributed data system can only guarantee two of three properties simultaneously: Consistency, Availability, and Partition Tolerance. Since network partitions are unavoidable in distributed systems, the practical choice is between consistency and availability during a partition.

The Three Properties

Consistency (C)

Every read receives the most recent write or an error. All nodes see the same data at the same time.
  • Example: After updating a user's email, every server immediately returns the new email
  • Tradeoff: May need to block requests until all nodes agree

Availability (A)

Every request receives a non-error response, without guarantee that it contains the most recent write.
  • Example: Every server always responds to queries, even if its data might be slightly stale
  • Tradeoff: May return outdated data during network issues

Partition Tolerance (P)

The system continues operating despite network partitions (messages being lost or delayed between nodes).
  • Example: If the network between two data centers fails, both continue serving requests
  • Tradeoff: Must choose between C and A when a partition occurs

The Real Choice: CP vs AP

In practice, network partitions will happen. So the real question is:

ChoiceBehavior During PartitionExample Databases
CP (Consistent + Partition-tolerant)Refuses some requests to ensure consistencyMongoDB, HBase, Redis Cluster, etcd
AP (Available + Partition-tolerant)Serves all requests but may return stale dataCassandra, DynamoDB, CouchDB, Riak
CA (Consistent + Available)Not possible in distributed systems (only single-node like PostgreSQL)PostgreSQL (single node), MySQL (single node)

CAP in Practice: Data Engineering Examples

  • Metadata catalog (e.g., Hive Metastore): Needs CP — inconsistent metadata causes wrong query results
  • User session store (e.g., Redis): Usually CP — stale sessions cause auth issues
  • Event log (e.g., Kafka): AP — better to accept events during partitions than reject them
  • Shopping cart (e.g., DynamoDB): AP — availability matters more than perfect consistency

PACELC: Extending CAP

The PACELC theorem extends CAP: even when there is no partition, there is still a tradeoff between Latency and Consistency.

If Partition → choose A or C
Else → choose L (Latency) or C (Consistency)

Example: DynamoDB is PA/EL (Available during partitions, Low latency normally). MongoDB is PC/EC (Consistent always, even at higher latency).

Key Points

Gotchas

CAP pitfalls that trip up practitioners:

  • "CP" and "AP" are not all-or-nothing — most systems are tunable. Cassandra lets you pick consistency per operation (ONE, QUORUM, ALL, LOCAL_QUORUM). MongoDB read/write concerns (majority, local, snapshot). Tuning sloppily is the biggest source of "we chose an AP database but wanted consistency" bugs.
  • CAP is about the partition moment, not normal operation. During healthy operation, most AP databases give you near-consistent reads. The test is what happens during a network partition. Many teams never test this until it happens in prod and behavior surprises them. Chaos-engineer network partitions in staging before trusting a system with critical data.
  • PACELC extends CAP and matters more day-to-day. Even without partition, there's a tradeoff between Latency and Consistency. DynamoDB is PA/EL (available during partition; low-latency, eventually-consistent normally). Spanner is PC/EC (consistent even during partition; consistent and slower normally). Understand your system's PACELC classification.
  • Consistency guarantees differ subtly. Strong consistency, linearizability, serializability, snapshot isolation, causal consistency, eventual consistency — these are NOT synonyms. Read the docs; "consistency" means different things in different systems.
  • CAP doesn't apply to single-node databases the same way. PostgreSQL on a single node is "CA" only because partitions can't happen by definition. Multi-node Postgres (streaming replication, Patroni) must make real CAP choices.
  • Availability isn't uptime; it's per-request success. A CP system that refuses 20% of requests during a partition is still technically "up." Measure request-level availability, not node-level uptime, to understand actual user impact.
  • Network partitions happen inside datacenters, not just between regions. A rack-to-rack network blip, a bad switch, an overloaded TOR — all cause partitions. Don't assume partitions only happen during AWS outages.
  • Split-brain is the failure mode, not the feature. When an AP system accepts writes on both sides of a partition, you end up with divergent history that needs conflict resolution. Last-write-wins is simple; CRDTs are smarter; custom merge logic is application work nobody budgets for.

Frequently Asked Questions

What is the CAP theorem in simple terms?

CAP theorem says a distributed database can guarantee at most two of three properties: Consistency (every read sees the latest write), Availability (every request gets a response), and Partition Tolerance (the system keeps working when the network splits). Since network partitions are inevitable in real systems, you effectively must choose between Consistency and Availability. CP systems refuse requests during partitions to ensure correctness; AP systems serve requests with potentially stale data. The choice shapes how your database behaves when things go wrong.

Is Kafka CP or AP?

Kafka is configurable. With `acks=all` plus `min.insync.replicas=2` on a 3-replica topic, Kafka behaves CP — it refuses writes if fewer than 2 in-sync replicas are available, guaranteeing data isn't lost. With `acks=1`, Kafka is more AP — the leader accepts writes without waiting for replicas, at risk of data loss during leader failure. Most Kafka deployments for critical data use `acks=all` + `min.insync.replicas=2`, which is CP for durability purposes. Read your producer/broker settings carefully — the defaults aren't always safe for the workload.

Why can't a distributed system have all three CAP properties?

During a network partition, a node receiving a write has two choices: (a) accept the write locally and risk divergence from other nodes that can't see it (sacrifice Consistency), or (b) refuse the write until it can confirm with other nodes (sacrifice Availability). You cannot do both simultaneously — physics. Partition Tolerance isn't really optional in a distributed system because you can't prevent networks from failing. So CAP reduces to a choice between C and A when P is assumed.

Does the CAP theorem matter for data engineering?

Yes, when picking infrastructure components. A metadata catalog needs CP — inconsistent metadata causes wrong query results. An event bus for analytics usually wants AP — better to accept events during partitions than reject them and lose telemetry. A session store depends on use case: auth sessions want CP (stale sessions cause auth bugs), cache sessions can be AP. When evaluating Snowflake vs. DynamoDB vs. Redis vs. Kafka for a pipeline role, CAP classification (plus PACELC) is one of the lenses you use to match the tool to the workload.

What is the PACELC theorem?

PACELC extends CAP: "if Partition, choose Availability or Consistency; Else, choose Latency or Consistency." Even with no partition, there's still a tradeoff between consistency (wait for all replicas to agree) and latency (respond from one replica, maybe stale). DynamoDB is PA/EL — favors availability during partitions and low-latency during normal operation. Google Spanner is PC/EC — favors consistency even during partitions, even at some latency cost. PACELC is more useful than CAP day-to-day because partitions are rare but latency tradeoffs happen constantly.

Which databases are CP and which are AP?

CP (refuses writes during partition for correctness): MongoDB with majority write concern, HBase, Redis Cluster, ZooKeeper, etcd, CockroachDB, Google Spanner, FoundationDB. AP (accepts writes during partition, reconciles later): Cassandra, DynamoDB (in its default configuration), Riak, CouchDB, Amazon Aurora readers, most DNS systems. Many systems are tunable — Cassandra can be "more CP" with ALL consistency level; DynamoDB has Strong Consistency read mode. Don't memorize the list; read your specific system's docs on partition behavior.

Can a single-node database have all three CAP properties?

Technically a single-node database can be "CA" because partitions are impossible when there's only one node — there's nothing to partition from. PostgreSQL, MySQL, SQLite on a single instance are commonly described this way. But the moment you add replication, failover, or multi-node deployment, you must make CAP choices. Streaming replication with synchronous commits is more CP; asynchronous replication is more AP. Patroni-managed Postgres clusters make explicit choices about partition behavior. Single-node "CA" is a limit case, not a real distributed property.

Related Terms

ACID TransactionsData WarehouseApache KafkaData Modeling

Related Tools

CassandraDynamoDBMongoDBApache KafkaRedis

Learn More

Browse All Terms Read Articles