Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
CP vs AP databases: what happens during a partition?
This trade-off only exists during an actual network partition. The rest of the time, a well-designed system can be both consistent and available — which is why the popular "pick 2 of 3, always" version of CAP theorem is a little bit wrong.
The one distinction that decides everything
Rooted in CAP theorem: during a network partition, a distributed database must choose between Consistency (every read sees the latest write, but the system may refuse some requests) and Availability (every request gets a response, but it might be stale). CP systems pick consistency under a partition; AP systems pick availability. Partition tolerance itself is treated as a given — real networks partition, so it isn't the choice being made.
Is stale data worse than no data for this piece of state? CP. Is refusing service worse than briefly-stale data? AP. This decision is made per data type, not once for a whole system.
Head to head
| Dimension | CP | AP |
|---|---|---|
| Under a partition | Some nodes refuse to serve rather than risk stale data | All reachable nodes keep serving, possibly stale/conflicting data |
| Consistency model | Strong / linearizable | Eventual — reads may be stale until convergence |
| Example systems | ZooKeeper, etcd, HBase, Spanner (with tight clock sync) | Cassandra, DynamoDB (default), CouchDB, Riak |
| Conflict handling | Prevented by design — writes serialized via consensus | Allowed, then resolved — LWW, vector clocks, CRDTs |
| Write availability during partition | Minority side can’t write — waits or errors | Every reachable node accepts writes, always |
| Read guarantee | Linearizable reads (served via the leader or a quorum) return the latest committed value or an error — never stale | May return an outdated value, but always returns something |
| Best for | Financial ledgers, config stores, distributed locks | Shopping carts, social feeds, session data |
When to reach for each
Reach for CP
- Correctness of the value matters more than uptime
- Bank balances, distributed locks, leader election
- Inventory counts where overselling is a real cost
- Config that must never diverge across nodes
Reach for AP
- Uptime matters more than perfect freshness
- A briefly-stale shopping cart or feed is fine
- Refusing service would be worse than serving old data
- Per-query tunable consistency is available (quorum reads/writes)
Most real systems pick per data type, not once
The CP/AP label rarely applies uniformly across a whole product. An e-commerce platform commonly runs the shopping cart AP (a brief hiccup shouldn't block adding an item) and the final checkout/inventory-decrement CP (that specific write genuinely can't tolerate a stale double-sell). Many "AP" systems like Cassandra also let you tune consistency per query via quorum settings — meaning the CP/AP label often describes a DEFAULT or an extreme end of a dial, not a permanent, unchangeable binary choice.
Ask the question per piece of state, not per system: "if this specific write is briefly unavailable during a partition, is that better or worse than it being briefly wrong?"
This trade-off only bites during an actual partition
It's worth being precise about what CAP theorem actually constrains, because it's commonly overstated. The forced choice between consistency and availability applies ONLY during an actual network partition — nodes genuinely unable to reach each other. Most of the time, with no partition happening, a well-designed system can be both consistent and available simultaneously; there's no theorem forcing a permanent sacrifice of one for the other in normal operation. The popular shorthand "pick 2 of 3, always" is a mis-simplification of a narrower, more useful statement: partitions WILL eventually happen in any real distributed system — that part isn't optional or a choice you get to avoid by careful engineering — and CAP describes the forced choice you must make specifically for the DURATION of that partition, not a permanent architectural ceiling you live under forever.
This precision matters practically: a system doesn't need to decide "I am a CP system" or "I am an AP system" as an eternal identity — it needs to decide, for each piece of state, what should happen in the specific window where nodes can't talk to each other. That's a much narrower, more answerable design question than the theorem's popular framing suggests.
You're not choosing consistency or availability forever — you're pre-deciding what a specific piece of data should do during the finite window of an actual partition, which is a much smaller and more tractable decision than it sounds.
A worked scenario: cart vs checkout on the same platform
An e-commerce platform's shopping cart service is built AP (Cassandra/DynamoDB-style): if a data-center link partitions, the cart keeps accepting adds and removes on both sides of the partition and reconciles later — refusing to let someone add an item during a brief network hiccup would just lose a sale for no real benefit, since a cart being briefly inconsistent across replicas costs nothing serious.
The SAME platform's checkout-time inventory decrement is built CP, routed through a strongly-consistent store or leader — because during that same partition, letting both sides independently decrement the last unit of a sold-out item would double-sell it, a real, costly correctness failure. Refusing the write until consistency is restored — telling some users "try again" — is the correct trade here, even though it's the opposite choice the cart made one service over. Same platform, same partition event, two deliberately different answers.
The question was never "is this platform CP or AP" — it was "for this specific write, is stale worse than unavailable," asked and answered separately for the cart and for the inventory decrement.
The picture: one partition, two behaviours
Common mistakes
Most CP/AP bugs are not a wrong choice of database. They come from assuming the label promises more than it does. Each of these lives at an edge the label hides: a write that half-failed, a replica that lags, two clocks that disagree, a request that lands on a different node.
- Treating QUORUM as CP
Cassandra at
QUORUMfor reads and writes gives R + W > N, so every read set overlaps the latest write set. That is not linearizable. A write that failed after reaching one replica is not rolled back, and a later read can return it. Concurrent writes are settled by timestamp, so one silently loses. On the minority side of a partition,QUORUMrequests simply fail. You lose availability and still don’t get consistency. For a real compare-and-set, use a lightweight transaction (IFclauses, built on Paxos), or a CP store. - Assuming every CP read is fresh
The head-to-head table’s “never stale” holds only for linearizable reads, the ones that go through the leader or a quorum, and not every CP read is one. ZooKeeper answers reads from whichever server the client is connected to, and that server can lag; call
syncfirst when it matters. An etcd “serializable” read is answered by the local member and can be stale too. Even a leader answering from local state can be stale if it has been deposed without knowing. CP describes the writes; check how your reads are served. - Last-write-wins on data that must not lose writes
Last-write-wins keeps whichever write has the later timestamp and throws the other away, with no error. Clock skew between nodes can even make the older write win. For a cart, two adds on two sides of a partition become one add. Merge instead: the Dynamo paper merged carts by taking the union, and accepted that a deleted item could reappear. CRDTs make that kind of merge exact. If you must use last-write-wins, take timestamps from one well-behaved source, such as a hybrid logical clock, and log the losing writes so a lost update can at least be found.
- Forgetting the cost when nothing is broken
CAP only forces a choice during a partition, but strong consistency is not free the rest of the time. A linearizable write must reach a majority, so if replicas sit in different regions, every write pays a cross-region round trip. The PACELC framing names this: when there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency. The latency side of that is the one you pay every day. So ask two questions of each piece of state: what should it do during a partition, and how much latency is consistency worth on every normal request?
- Breaking read-your-writes on an AP store
A user saves their profile, the next request goes to a different replica, and the old profile comes back. To them that looks like the save failed, and they save again. AP stores need session guarantees for this: route a user’s reads to the replica that took their write, read at a stronger level right after a write, or carry a version token the replica must reach before it answers. Monotonic reads is the sibling bug: a refresh lands on a staler replica, and a comment the user already saw disappears.
Where this shows up in production and interviews
Real databases rarely sit at one end of the dial. Each of these exposes the choice as a setting, made per table or per request, which is the page’s per-data-type rule built into the API.
- DynamoDB: a dial per request
DynamoDB reads are eventually consistent unless the request sets
ConsistentRead, and an eventually consistent read costs half the read capacity. That is the trade-off with a price on it. Global tables replicate between regions asynchronously and settle conflicting writes by last writer wins. So data written in two regions at once has the cart problem above. Queries on a global secondary index are always eventually consistent; the flag does not apply there. - Cassandra: the level is a per-query choice
ONE,QUORUM,LOCAL_QUORUMandALLtrade latency and availability against overlap with the latest write. Multi-datacenter deployments commonly useLOCAL_QUORUMso a request never waits on another region. Writes that must not race, such as claiming a username, use a lightweight transaction. A quick check: with replication factor 3,QUORUMis 2, so one replica can be down and both reads and writes still succeed.ALLfails as soon as any one replica is unreachable. - Spanner and CockroachDB: CP SQL
Both replicate each piece of data through consensus, so the side of a partition without a majority cannot write it. Spanner also waits out its clock uncertainty before acknowledging a commit (“commit wait”), so timestamps match real time order. That wait is the latency cost from the PACELC mistake above, paid on every commit to keep consistency. CockroachDB serves reads from each range’s leaseholder, and offers follower reads as an opt-in for queries that can accept slightly stale data in exchange for a nearby replica.
- The interview version
In “design a key-value store” or “design a shopping cart”, the interviewer is waiting for the partition question. Answer per piece of state, as the page argues. Then go one level deeper: give N, R and W, say how conflicts resolve (last-write-wins, vector clocks or a merge), and say what a client on the minority side sees. For the cart, that might be N = 3 with W = 2 and R = 2 normally, so R + W > N. During a partition, accept writes on either side and merge by union when it heals. Checkout reads stock from the CP store. Ending with “we use Cassandra, so it’s AP” misses the point.
Which would you pick?
Three situations. Pick the side you'd actually build — the explanation follows.
A payments ledger. A network partition splits your cluster and a write arrives on the minority side.
Money is the canonical CP case: accepting a write you cannot order against the other side risks double-spending, and "reconcile afterwards" means the incorrect balance was already visible and possibly acted on. Refusing the write is an outage; accepting it is a corruption, and corruption is the more expensive of the two.
A "last seen online" indicator on a social profile, replicated across three regions, during a partition between two of them.
The cost of a slightly stale timestamp is close to zero, and the cost of the feature going dark is a visibly broken profile. This is exactly where availability wins. Treating consistency as a universal default is the mistake the page argues against — the right choice comes from what the data costs when it is wrong.
A colleague says "we chose CP, so the system is consistent — we do not need to think about partitions."
CAP is a statement about behaviour *during* a partition, not a way to avoid one. Choosing CP means choosing to become unavailable, so the partition is still an event your callers experience and your code must handle — with timeouts, retries and a degraded path. The choice moves the failure; it does not remove it.
Quick answers
CP or AP — which should I use?
Decide per data type: if stale data is worse than no data (financial balances, distributed locks, inventory counts), choose CP. If refusing service is worse than briefly-stale data (shopping carts, feeds, session state), choose AP. Most real systems use both, for different pieces of state.
Does CAP theorem mean I always sacrifice consistency or availability?
No — the forced trade-off only applies during an actual network partition. Without a partition, a well-designed system can be both consistent and available. The theorem describes the choice you must make for the duration of a partition, not a permanent limitation.
Can a system be both CP and AP?
Not for the same piece of data during a partition — but a single system commonly runs different services or data types with different CP/AP choices (e.g. an AP cart and a CP checkout), and many AP systems let you tune consistency per query via quorum settings.
What happens to a CP system during a partition?
The minority side of the partition (the side that can’t confirm it has the latest state via consensus) refuses to serve some requests — typically writes, sometimes reads — rather than risk returning or accepting a value that could conflict once the partition heals.
CP vs AP databases: what happens when the network splits?
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The System Design Fundamentals HandbookThe load-bearing ideas behind every distributed system — the CAP theorem and consistency models, concurrency and locking, partitioning and replication, and consensus and coordination — each tied to a real worked design you can study interactively.Read →
- CAP Theorem & Consistency ModelsWhat a distributed system can promise when the network splits — CP vs AP, why "CA" is a myth, PACELC, and the full spectrum from linearizable to eventual consistency. Part of System Design Fundamentals.Read →
- Partitioning, Sharding & ReplicationHow one dataset becomes many — range vs hash partitioning, consistent hashing and virtual nodes, hot partitions, replication topologies, replication lag, and quorums. Part of System Design Fundamentals.Read →
- Consensus, Transactions & CoordinationHow nodes that can crash still agree on one truth — majority quorums, Raft and Paxos, leader election, two-phase commit vs the saga pattern, and idempotency for exactly-once effects. Part of System Design Fundamentals.Read →
- The Kubernetes HandbookThe one idea under all the YAML — declare desired state, and a control loop makes reality match. Covers the orchestration problem, pods, deployments and replicasets, services and networking, the reconciliation loop and self-healing, the scheduler, config/secrets and health probes, autoscaling, and when you actually need Kubernetes.Read →
- The Observability HandbookSeeing inside production — monitoring vs observability, the three pillars (metrics, logs, traces) and what each answers, structured logging, metric types and the cardinality trap, distributed tracing, the golden signals and SLIs/SLOs/error budgets, alerting on symptoms not causes, and correlating all three during an incident.Read →