|$ curl https://forge-ai.dev/api/markdown?path=docs/system-design/cap-theorem
$cat docs/cap-&-pacelc.md
updated Recently·25 min read·published

CAP & PACELC

System DesignIntermediate🎯Free Tools
Introduction

The CAP theorem is one of the most cited results in distributed systems. It states that any distributed data store can provide at most two of the following three properties: Consistency, Availability, and Partition tolerance. In practice, because networks are unreliable, partition tolerance is not optional — so the real tradeoff is between consistency and availability.

PACELC extends CAP by recognizing that even when there is no partition, there is a tradeoff between Latency and Consistency. Together, CAP and PACELC provide a useful vocabulary for reasoning about distributed database design.

This guide explains the theorem clearly, debunks common misconceptions, and shows how real systems make these tradeoffs every day.

CAP Defined

CAP uses three properties with specific technical meanings. It is important not to confuse colloquial usage with the theorem's definitions.

PropertyMeaningPlain English
ConsistencyEvery read receives the most recent write or an errorAll nodes agree on the same data
AvailabilityEvery request receives a non-error response, without guarantee it contains the most recent writeThe system responds, possibly with stale data
Partition toleranceThe system continues to operate despite arbitrary message loss or failure of part of the systemThe system survives network partitions
📝

note

Consistency in CAP means linearizability — a very strong guarantee. It is not the same as the C in ACID, though the ideas are related. Availability in CAP means every working node responds to every request, not just 99.9% uptime.
Why Partition Tolerance Is Not Optional

A network partition occurs when nodes cannot communicate with each other. Partitions are inevitable: switches fail, packets are dropped, regions lose connectivity, and GC pauses delay heartbeats. A system that is not partition-tolerant would halt whenever the network hiccups, making it unsuitable for real distributed deployments.

partition.txt
TEXT
1Network partition scenario:
2
3┌───────────┐ X ┌───────────┐
4│ Node A │◄────partition──►│ Node B │
5│ (primary)│ │ (replica)│
6└───────────┘ └───────────┘
7
8A client writes to Node A. Node B does not see it.
9
10Choices:
111. Wait for B to acknowledge → Consistent but unavailable
122. Acknowledge immediately → Available but inconsistent
133. Refuse all writes → Consistent but unavailable
14
15CAP says you cannot be both consistent and available
16while the partition exists.

best practice

In interviews, do not say "we choose two of three." Say "we are partition-tolerant, and during a partition we prioritize consistency or availability depending on the use case."
CP vs AP Systems

CP systems choose consistency over availability during a partition. They refuse requests or block until the partition heals to avoid serving stale data. AP systems choose availability over consistency during a partition. They continue serving reads and writes, accepting that replicas may diverge temporarily.

SystemClassWhy
PostgreSQL (single node)CAConsistent and available, not distributed
etcd / ZooKeeperCPConsensus; leader refuses writes without quorum
CassandraAP tunableContinues serving; consistency level per query
DynamoDBAP tunableEventually consistent by default; strongly consistent reads optional
MongoDB (default)CPPrimary acknowledges writes; reads from primary

info

Most modern databases are not purely CP or AP. They let you tune consistency per operation. Cassandra's ONE, QUORUM, and ALL consistency levels are the textbook example.
PACELC

PACELC, proposed by Daniel Abadi, extends CAP with the observation that even when there is no partition, there is a tradeoff between Latency and Consistency. The acronym reads: "If there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency."

pacelc.txt
TEXT
1PACELC breakdown:
2
3P → Partition
4A → Availability
5C → Consistency
6E → Else (no partition)
7L → Latency
8C → Consistency
9
10If Partition:
11 choose Availability OR Consistency (CAP)
12Else (no partition):
13 choose Latency OR Consistency
14
15Examples:
16- DynamoDB default: PA/EL
17 Partition → Available; Else → Low latency
18- Spanner: PC/EC
19 Partition → Consistent; Else → Consistent (with TrueTime)
20- Cassandra with QUORUM: PA/EC
21 Partition → Available; Else → Consistent
📝

note

PACELC is more practical than CAP because it acknowledges that latency and consistency trade off even in normal operation. Replicating synchronously to multiple regions gives strong consistency but adds tens to hundreds of milliseconds.
Consistency Models

Consistency is not binary. There is a spectrum from strong to weak, each with different guarantees and costs. Choosing the right model depends on what correctness means for your application.

ModelGuaranteeExample Use Case
Strong / LinearizableEvery operation appears to happen atomically at one point in timeBank account balances
SequentialAll operations appear in some total order consistent with real-timeCollaborative editing
Causal causally related operations are seen in orderMessaging, comments
EventualIf no new updates, replicas convergeSocial like counts, CDNs

best practice

Use the weakest consistency model that satisfies correctness requirements. Strong consistency is expensive; eventual consistency is often good enough for user-facing counts, recommendations, and search indexes.
Real-World Tradeoffs

The CAP/PACELC framework is most useful when applied to concrete design decisions. Here are common scenarios and the consistency choices that make sense.

ScenarioPriorityTypical Choice
Payment processingConsistencyCP, strongly consistent ledger
Product catalogAvailability + latencyAP, cached eventually consistent reads
Session storeLatencyAP in-memory replicated cache
Inventory reservationConsistencyCP with optimistic locking
Analytics pipelineAvailability + throughputAP event streaming
🔥

pro tip

In interviews, avoid saying "we need strong consistency everywhere." That is almost never true and reveals a lack of understanding of cost. Map each data type to the appropriate consistency model.
Practical Consistency Tuning

Modern distributed databases rarely force a global CP or AP choice. Instead, they expose tunable consistency levels per operation. Understanding these knobs lets you optimize for latency and correctness without changing databases.

consistency-levels.txt
TEXT
1Cassandra consistency levels:
2
3ONE: Read/write acknowledged by one replica
4 Fastest, lowest consistency
5
6QUORUM: Read/write acknowledged by majority of replicas
7 Balanced consistency and availability
8
9ALL: Read/write acknowledged by all replicas
10 Strongest consistency, lowest availability
11
12LOCAL_QUORUM: Quorum within the local data center
13 Avoids cross-DC latency for regional workloads
14
15EACH_QUORUM: Quorum in every data center
16 Strong global consistency, higher latency
PatternRead ConsistencyWrite ConsistencyResult
Max availabilityONEONEFastest, eventual consistency
BalancedQUORUMQUORUMRead-your-writes for most cases
StrongALLALLLinearizable, fragile
Fast local reads, strong writesLOCAL_ONEEACH_QUORUMDurable writes, fast local reads

warning

Combining inconsistent read and write levels can produce surprising results. If you write with ONE and read with ALL, you may read stale data until the other replicas catch up. Always verify the combination gives the guarantee you expect.
$Blueprint — Engineering Documentation·Section ID: SD-CAP-01·Revision: 1.0