#12 CAP Theorem & Trade-offs – Consistency, Availability, Partition Tolerance

The Distributed Database Dilemma

A global e-commerce company faced a problem. Customers from different countries reported inconsistent order statuses.

Sometimes, orders appeared instantly. Other times, updates took minutes. The engineers had to make a trade-off.

They couldn’t guarantee strong consistency, high availability, and fault tolerance all at once. They had to follow the CAP theorem.

What is the CAP Theorem?

The CAP Theorem, formulated by Eric Brewer, states that a distributed system can provide only two out of three guarantees:

  • Consistency (C) – Every read returns the most recent write.

  • Availability (A) – The system remains responsive even if some nodes fail.

  • Partition Tolerance (P) – The system functions despite network failures.

    diagram showing the CAP triangle with trade-offs between C, A, and P

Breaking Down CAP Theorem

Before learning about CAP theorem, it is necessary for us to know about C,A and P in CAP theorem.

1. Consistency (C) – Always Correct Data

Every read receives the latest committed write, ensuring no stale data.

✔ Pros: Reliable and accurate data. ✖ Cons: Can slow down response times, as all nodes must sync.

Example: A traditional relational database (e.g., PostgreSQL) ensures strict consistency.

2. Availability (A) – Always Responsive

The system remains operational even if some nodes fail.

✔ Pros: Ensures uptime and responsiveness. ✖ Cons: Data might be outdated due to delays in synchronization.

Example: DNS servers prioritize availability—resolving domain names even if some servers are down.

3. Partition Tolerance (P) – Survives Network Failures

The system continues to operate despite network partitions (communication breakdowns between nodes).

✔ Pros: Essential for distributed systems spanning multiple locations. ✖ Cons: Forces a trade-off between consistency and availability.

Example: A globally distributed NoSQL database like Cassandra remains functional even if some data centers go offline.

CAP Trade-offs in Real-World Systems

Since partition tolerance (P) is unavoidable in distributed systems, architects must choose between:

1. CP (Consistency + Partition Tolerance) – Strong Consistency

  • Guarantees accurate data but sacrifices availability during network failures.

  • Used for financial systems where incorrect transactions are unacceptable.

✔ Example: Google Spanner, relational databases with distributed transactions.

2. AP (Availability + Partition Tolerance) – High Availability

  • Ensures the system remains responsive but may return slightly outdated data.

  • Ideal for social media feeds, product listings, and caching.

✔ Example: Amazon DynamoDB, where availability is prioritized over strong consistency.

3. CA (Consistency + Availability) – Single Node Systems

  • Provides both consistency and availability but does not tolerate partitions.

  • Suitable for non-distributed databases running on a single machine.

✔ Example: Traditional SQL databases (MySQL, PostgreSQL) without replication.

Choosing the Right Model

Requirement

Best CAP Model

Example Systems

Bank Transactions

CP

Google Spanner, Zookeeper

Online Shopping Cart

AP

Amazon DynamoDB, Cassandra

Local Database Storage

CA

MySQL, PostgreSQL

Conclusion

Distributed systems must balance consistency, availability, and partition tolerance, but they cannot achieve all three.

  • CP systems ensure correctness but may be unavailable during failures.

  • AP systems remain accessible but may serve slightly outdated data.

  • CA systems work only when there are no partitions.

Next, we’ll explore Latency, Throughput & Performance Optimization – Network Latency, Processing Latency.

Powered by wisp

3/3/2025
Related Posts
#25 Data Consistency & Storage Strategies – ACID, BASE, Event Sourcing, CQRS

#25 Data Consistency & Storage Strategies – ACID, BASE, Event Sourcing, CQRS

Canceled rides showing as active? Learn about data consistency! We'll show you how ACID, BASE, Event Sourcing, and CQRS ensure accurate data in your apps. Keep your users happy with reliable information.

Read Full Story
#10 Eventual Consistency & Distributed Data Stores – Cassandra, DynamoDB, CRDTs

#10 Eventual Consistency & Distributed Data Stores – Cassandra, DynamoDB, CRDTs

Delayed notifications? Don't worry, it's probably eventual consistency. Let's chat about Cassandra, DynamoDB, and CRDTs – how they keep huge systems alive and kicking, even when things get messy.

Read Full Story
#16 Consensus Algorithms & Distributed Coordination – Paxos, Raft, 2PC, Gossip Protocol

#16 Consensus Algorithms & Distributed Coordination – Paxos, Raft, 2PC, Gossip Protocol

Ever wonder how banks keep your balance right across all their servers? We'll dive into consensus algorithms like Paxos, Raft, and 2PC. Basically, how to make sure everyone's on the same page in a big system.

Read Full Story
© Rahul 2025
    #12 CAP Theorem & Trade-offs – Consistency, Availability, Partition Tolerance - Rahul Vijay