What is the CAP theorem?

The CAP theorem states that a distributed data system can guarantee at most two of three properties at the same time: Consistency, Availability, and Partition Tolerance, forcing architects to make deliberate trade-offs when network partitions occur.

Key Points: • Consistency means every node returns the same, most recent data for a given read, no matter which node handles it. • Availability means every request receives a non-error response, even if it isn't the most recent data. • Partition Tolerance means the system keeps operating despite network failures that prevent some nodes from communicating. • Since network partitions are unavoidable in real distributed systems, the practical choice is usually between prioritizing consistency (CP) or availability (AP) during a partition. • Many modern systems adopt eventual consistency, an AP-leaning approach, and reconcile data once the partition resolves.

Example: A globally distributed database like Cassandra is typically tuned as an AP system, staying available and serving possibly stale reads during a network partition, while a system like a traditional relational database cluster with synchronous replication leans CP, refusing writes rather than risking inconsistency.

Interview Tip: A concise interview answer is:

"The CAP theorem says a distributed system can only guarantee two of Consistency, Availability, and Partition Tolerance at once. Since partitions are inevitable, the real choice in practice is between staying available with possibly stale data, an AP system, or staying strictly consistent by rejecting requests during a partition, a CP system."