CAP & PACELC
During a network partition, a replicated system either refuses some requests (consistency) or serves possibly stale data (availability). PACELC adds: otherwise, every request trades latency against consistency.
Analogy: Two bank branches lose their phone line. Either both stop approving withdrawals until it's back (consistent), or both keep approving and reconcile later, risking an overdraft (available).
How it works
- C means acting like one up-to-date copy; a side that can't confirm the latest value errors or waits.
- CA isn't a real choice: partitions will happen; a single node is "CA" only because it isn't distributed.
- PACELC covers normal operation: every request either waits for remote replicas or answers from the nearest one.
- Spanner is PC/EC and pays cross-region commit latency; Dynamo-style stores are PA/EL, tunable per query with quorums.
- Decide per operation: slightly stale vector chunks are fine (PA/EL); a stale permission check is not (PC/EC).
Check yourself
Answer to mark it learned; your answers aren't scored.
Your RAG assistant runs in us-east and eu-west with async replication. The inter-region link drops for 4 minutes. In the EU region, how should chunk retrieval and ACL (permission) reads behave?
Go deeper
Full explanation
CAP (Brewer's conjecture, proved by Gilbert & Lynch in 2002) says that when a network partition splits your replicas, each side must choose:
- C (consistency): act like one up-to-date copy (linearizability). A side that can't confirm the latest value returns an error or waits.
- A (availability): every live node answers, even if the answer is stale.
"CA" is not a real option. You can't opt out of partitions in a distributed system; P is a fact, and the choice only kicks in when one happens. A single-node database is "CA" only because it isn't distributed.
PACELC (Abadi) fixes CAP's blind spot: partitions are rare, but replication costs you on every request. If Partition, choose A or C; Else, choose Latency or Consistency: wait for remote replicas, or answer from the nearest one.
- Spanner: PC/EC, consistent always, pays cross-region commit latency.
- Dynamo-style (Cassandra, Riak): PA/EL by default, tunable toward C per query with quorums.
Decide per operation, not per database. In an AI app, a vector index replica serving chunks a few seconds stale is fine (PA/EL); a permission check that lets someone retrieve a document they just lost access to is not (PC/EC), see Metadata filters & permission-aware retrieval.
Code Choosing PA/EL or PC/EC per query in Cassandra
from cassandra import ConsistencyLevel
from cassandra.cluster import Cluster
from cassandra.query import SimpleStatement
session = Cluster(["10.0.0.1", "10.0.0.2"]).connect("kb") # keyspace with RF=3
# PA/EL: answer from 1 replica. Fast, survives a partition, may be stale.
get_chunks = SimpleStatement(
"SELECT text FROM chunks WHERE doc_id = %s",
consistency_level=ConsistencyLevel.ONE)
# PC/EC: 2 of 3 replicas must answer (QUORUM writes + QUORUM reads overlap).
# If only 1 replica is reachable, this raises Unavailable instead of guessing.
can_read = SimpleStatement(
"SELECT allowed FROM acl WHERE user_id = %s AND doc_id = %s",
consistency_level=ConsistencyLevel.QUORUM)
def fetch(user_id, doc_id):
row = session.execute(can_read, (user_id, doc_id)).one()
if not (row and row.allowed): # fail closed on deny or unknown
raise PermissionError(doc_id)
return [r.text for r in session.execute(get_chunks, (doc_id,))]Real example
A company runs its RAG assistant in us-east and eu-west, with the vector index replicated asynchronously. The link between regions drops for 4 minutes.
- Chunks: EU keeps answering from its replica, just missing documents ingested in the US during those minutes. Acceptable: PA/EL.
- ACLs: an employee was removed from the M&A group in the US a minute earlier. If EU trusts its stale copy, it retrieves confidential chunks. So ACL reads require a quorum and fail closed when it's unreachable: PC/EC.
Same app, two different CAP choices.
Trade-offs +3 · −3
+ You gain
- Forces an explicit decision about partitions before an outage makes it for you.
- PACELC surfaces the everyday latency cost of consistency, which CAP ignores.
- Shared vocabulary to compare datastores: Spanner PC/EC, Cassandra PA/EL.
− You pay
- Narrow definitions: C means linearizability and A means every live node answers, so few real systems are purely either.
- Labels like "AP database" hide per-operation tuning (Cassandra, DynamoDB, MongoDB all expose it).
- Says nothing about slow nodes, partial failures or how long a partition lasts.
Use it when
When choosing a datastore or replication topology, especially multi-region, and when deciding per data type what happens if replicas can't talk to each other.
Avoid it when
As one label for a whole product ("we're AP"). Apply it per operation; for a single-node database it doesn't apply at all.
Numbers to know 4
- Cloud Spanner multi-region SLA: 99.999% (~5 min/year): a CP system can still be highly available.
- Inter-continent round trip ~70–150 ms: the floor for an EC write that must reach another region.
- N=3 replicas: R=2, W=2 overlap (R + W > N); R=1, W=1 is the fast EL setting.
- Elasticsearch/OpenSearch default refresh interval: 1 s; new documents aren't searchable until then.
Common pitfalls 4
- Claiming a distributed system is "CA": you don't get to skip partitions.
- Confusing CAP's C (linearizability) with ACID's C (integrity constraints).
- Picking one label for the whole system instead of deciding per operation and data type.
- Ignoring the else branch: partitions are rare, but latency vs consistency is paid on every request.
Interview questions 2
Answer out loud first, then reveal.
Is your design CP or AP?Show answer
It depends on the operation, and I'd say so explicitly. Chat history and RAG chunks are AP: a few seconds stale beats an error page. Billing, quotas and permission checks are CP: I'd rather return an error than double-charge or leak a document. Outside partitions, the PACELC question matters more because it's paid on every request: for most reads I choose latency with a bounded staleness I monitor, and pay for consistency only where correctness demands it.
Why isn't "CA" a valid choice?Show answer
Because once you have more than one node talking over a network, partitions happen: a switch fails, a long GC pause looks like a dead node. You can't decide not to tolerate them; you only decide what to do when one occurs, refuse or serve stale. Claiming CA really means "we assume the network never fails", which turns into an unplanned choice the first time it does. The only true CA system is a single node, and that isn't distributed.