What is the CAP theorem?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid System Design basics — a prerequisite for any developer role.
Answer
The CAP theorem (Brewer's theorem, 2000) states that a distributed data store can only guarantee two of the following three properties simultaneously: (1) Consistency (C): every read receives the most recent write or an error — all nodes see the same data at the same time. Like a single, up-to-date copy; (2) Availability (A): every request receives a response (not necessarily the most recent data) — the system is always up and responding; (3) Partition Tolerance (P): the system continues operating even if network messages are dropped or delayed between nodes (network partition). In a distributed system, partition tolerance is mandatory — network partitions happen and cannot be avoided. So the real choice is between C and A when a partition occurs: CP systems (Consistency + Partition Tolerance): during a partition, some nodes become unavailable to prevent inconsistency. Examples: HBase, MongoDB (strong consistency mode), ZooKeeper, etcd; AP systems (Availability + Partition Tolerance): during a partition, nodes stay available but may serve stale data. Examples: Cassandra, CouchDB, DynamoDB (default). The CA option is only possible in a single-node system (no partitions). Modern nuance: PACELC theorem extends CAP — even without partitions, there's a trade-off between latency and consistency.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a System Design codebase.