CAP Theorem

Concept. CAP says a distributed database can guarantee at most two of Consistency, Availability, and Partition tolerance, and since network partitions are a fact of life (P is mandatory), every real system trades off C against A.

Intuition. When a transatlantic cable cuts and Spotify's US and EU data centers can no longer talk, the system has to pick: either both regions stop accepting Premium upgrades until they reconnect (Consistency wins) or both keep taking writes that may conflict on reconnect (Availability wins). You don't get both during the partition; you only get to choose which one.

Pick Two (But It's Complicated)

The Harsh Reality

In college, you assume the network works. In distributed systems, you assume the network is actively trying to destroy your career. That's why Partition Tolerance is mandatory.

The CAP Theorem spectrum: trade-off between Consistency, Availability, and Partition tolerance

Real Systems: It's a Spectrum

SystemTypicallyTunable?Note
HDFS/HadoopCPNoStrict consistency for big data analytics
Amazon S3APNoHigh availability object storage (Eventual Consistency)
MongoDBCPYeswriteConcern, readConcern
CassandraAPYesQuorum reads/writes → CP
PostgreSQLCA*No*Single node only
DynamoDBAPYesEventually/Strong consistency
etcd/ConsulCPNoRaft consensus
CouchDBAPNoMulti-master, eventual
RedisCP/CAYesDepends on configuration

Key Takeaways

1. It's a Useful Model (Not a Law)

CAP isn't a strict rulebook. It's a framework for understanding trade-offs. Most systems offer tunable consistency levels, so use CAP to predict system behavior when things go south.

2. P is Not Optional

Network failures are a given. The real decision is between Consistency and Availability. Start by designing for partition tolerance.

3. Choose Based on Requirements

Align your system design with business needs. Financial systems demand Consistency. Social media thrives on Availability. Analytics can tolerate stale data, so Availability takes precedence.