CAP Theorem Real-World Examples: CP vs AP Databases

During a network partition, a distributed database must choose between two behaviors. A CP system (consistent and partition tolerant) refuses or delays some requests until it can confirm that the answer is current. An AP system (available and partition tolerant) answers every request, but some answers may be stale. Every real database makes one of these choices by default. Many also let you change it per request.

  • CP by default: ZooKeeper, etcd, HBase, MongoDB, Google Spanner.
  • AP by default: Cassandra, Amazon DynamoDB with eventually consistent reads, Riak, CouchDB.

The theorem itself is explained in What is the CAP theorem and what trade-offs does it imply for distributed databases?. This page stays with the systems and what each one does when the network breaks.

What each system chooses by default

SystemDefaultWhy
ZooKeeperCPWrites go through one leader and need a majority of servers to agree before they are confirmed.
etcdCPUses the Raft protocol; the minority side of a partition cannot keep a leader and stops serving writes.
HBaseCPEach region is served by exactly one region server; if that server is unreachable, its rows are unavailable until reassigned.
MongoDBCPOne primary per replica set; the default write concern of majority waits for most members before confirming.
Google SpannerCPPaxos groups and synchronized clocks; a partitioned minority stops answering rather than serve stale data.
CassandraAPAny replica accepts writes; a partitioned node keeps serving its own copy of the data.
Amazon DynamoDBAPReads are eventually consistent by default and may return data that is up to about a second old.
RiakAPModeled on Amazon's Dynamo design; conflicting writes are both kept and returned to the client to merge.
CouchDBAPEach node accepts writes on its own, and replication merges them later, keeping conflicts as revisions.

A third group is tunable. Cassandra has consistency levels such as ONE, QUORUM, and ALL. Each level sets how many replicas must respond before a read or write succeeds. DynamoDB accepts a strongly consistent read flag, which costs twice the read capacity of an eventually consistent read. Azure Cosmos DB offers five levels, from strong down to eventual. A tunable system is therefore CP or AP per request, not per database.

Four failure scenarios

etcd during a partition. A five-node cluster splits into a group of three and a group of two. The group of three still holds a majority, so it keeps a leader and accepts writes. A client connected to the group of two gets an error or a timeout on every write until the partition heals. Nothing stale is returned, and nothing confirmed is lost.

MongoDB during a partition. The primary is on the minority side and can no longer reach a majority of the replica set. It steps down within about ten seconds, and the majority side elects a new primary. A write confirmed with w: 1 but not yet replicated is rolled back when the old primary rejoins. With the default majority write concern, every confirmed write survives.

Cassandra during a partition. Two data centers lose their link. With consistency level ONE, a client in each data center keeps writing the same row, and each side confirms at once. When the link returns, Cassandra keeps the write with the latest timestamp and discards the other. This rule is called last write wins. The client whose write was discarded never learns that it was lost.

DynamoDB with eventually consistent reads. A client updates an item and reads it back a millisecond later from a different replica. The read can return the previous value, because that replica has not yet applied the write. Within about a second all replicas agree. A strongly consistent read would have returned the new value, at twice the cost.

PACELC: the trade-off when there is no partition

PACELC extends CAP with a second clause. If there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency. Even on a healthy network, a write that waits for a majority of replicas pays a round trip. That costs 1 to 5 milliseconds inside one region and 50 to 150 milliseconds across continents.

Spanner and etcd accept that delay in exchange for consistency. Cassandra and DynamoDB answer from the nearest replica and accept staleness in exchange for speed. What the stale side means for readers is described in What is Strong vs Eventual Consistency?.

How to answer "pick CP or AP for this system"

Use a two-line rule. Money, inventory, and anything with a uniqueness rule lean CP. A stale answer there produces a double spend, an oversold item, or a duplicate username. Feeds, counters, likes, and recommendations lean AP. A reader who sees a count that is a few seconds old loses nothing, while a refused request loses the reader.

State the rule, then name the partition behavior you accept. For a payment ledger: "I choose CP; during a partition the minority side returns errors and the client retries". For a like counter: "I choose AP; counts may differ by region for a few seconds and then converge". A mixed answer is often the right one. A store can keep stock levels CP and product reviews AP. How each service in a larger system makes its own choice is covered in How does the CAP theorem apply to microservices architecture?.

How to Prepare

  • Memorize the two lists above with one sentence of reasoning for each system. The interviewer usually asks for the reason, not the label.
  • Practice the partition story for one CP and one AP system out loud, in four sentences each. End with what the client sees.
  • Learn the consistency levels of Cassandra and DynamoDB. You should be able to explain that one database can be CP for one request and AP for the next.
  • Work through the consistency chapters in Grokking System Design Fundamentals, which cover CAP, PACELC, and consistency models with diagrams.
  • Design one ledger and one feed end to end in Grokking the System Design Interview, and justify the CP or AP choice in each.
TAGS
System Design Fundamentals
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What to Expect in the Anthropic System Design Interview
The commonly reported Anthropic system design questions (inference batching, high-throughput LLM serving, distributed search), what interviewers evaluate, and how to prepare.
Where to find detailed company-specific system design interview case studies
Find detailed company-specific system design interview case studies for Google, Meta, Amazon, Netflix, and Stripe. Covers formats, questions, rubrics, and prep resources.
What is the Two Generals' Problem?
System Design vs Software Architecture vs Software Design
Architecture is the set of structural decisions that are expensive to change, system design is the full concrete design of a system, and software design is the code inside one part.
What to Expect in the Intuit System Design Interview
Intuit design rounds run money-grade correctness at consumer scale, with tax season's extreme burst as the signature constraint and GenOS-era AI integration growing fast.
Free trials, pricing plans, and refund policies for grokking system design platforms
Compare pricing, free trials, and refund policies for Grokking System Design platforms. Covers Design Gurus, Educative, ByteByteGo, and free alternatives with ROI analysis.
Related Courses
New
Grokking Agentic Design Patterns course cover
Grokking Agentic Design Patterns
Design agents that act safely, recover from failure, and justify their cost.
4.9
(561 learners)
Discounted price for Your Region

$98

New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$98

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Design Gurus logo
One-Stop Portal For Tech Interviews.
About Us
Our Team
Careers
Partners
Contact Us
Become Affiliate
Copyright © 2026 Design Gurus, LLC. All rights reserved.