Explain the CAP theorem. What does it force you to choose between?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
The CAP theorem says a distributed data store can guarantee at most two of three properties during a network partition: Consistency (every read gets the latest write), Availability (every request gets a response), and Partition tolerance (the system survives network breaks). Since partitions are inevitable in distributed systems, the real choice is CP (consistent + partitioned-tolerant, sacrifice availability) versus AP (available + partitioned-tolerant, sacrifice strong consistency).
Detailed explanation
Eric Brewer's CAP theorem, proved by Gilbert and Lynch, defines three properties: Consistency means all nodes see the same data at the same time. Availability means every request receives a (non-error) response, without guarantee it is the latest. Partition tolerance means the system continues operating despite arbitrary network messages being dropped or delayed between nodes. The theorem: when a network partition occurs, you must choose between consistency and availability. A CP system (e.g., HBase, MongoDB with strong consistency, etcd) refuses operations that cannot be confirmed consistent during a partition — it returns errors to preserve correctness. An AP system (e.g., Cassandra, DynamoDB in eventual-consistency mode, Couchbase) keeps accepting reads and writes on whichever side of the partition is reachable, reconciling conflicts later. CA systems exist only in theory (or single-node databases) because a distributed system cannot avoid partitions. In practice, the choice is rarely binary — most systems tune where they sit on the spectrum per operation (e.g., DynamoDB offers both eventually-consistent and strongly-consistent reads). PACELC extends CAP to add latency-versus-consistency trade-offs even when the network is healthy. The practical takeaway: design for partition tolerance, then consciously pick your consistency-availability trade-off per feature.
Example
CP choice (banking ledger): during a partition, the account service rejects transfers rather than risk a double-spend — consistency over availability.
AP choice (social media feed): during a partition, users keep seeing and posting to their local region's view; likes and comments reconcile when the partition heals — availability over immediate consistency.Interview tip
State the theorem crisply, then immediately say 'in practice the choice is CP vs AP because partitions are unavoidable.' Give one concrete CP and one AP example. Naming PACELC as the extension signals depth without derailing the answer.
Common mistakes
- Saying a system can be all three — it cannot during a partition.
- Treating CAP as a binary all-or-nothing choice rather than a spectrum.
- Forgetting that partition tolerance is not optional in distributed systems.