Skip to main content

Command Palette

Search for a command to run...

Day 10: CAP Theorem in Real Systems (CP vs AP choices)

Published
2 min read

Hello guys, when designing distributed systems, we quickly face trade-offs. The CAP Theorem, introduced by Eric Brewer, formalizes this:

In any distributed data system, you can only guarantee two out of three:
Consistency, Availability, Partition Tolerance.

Since network partitions are inevitable in real-world distributed environments, the real choice is between CP (Consistency + Partition Tolerance) and AP (Availability + Partition Tolerance).


🔹 Quick Refresher

  • Consistency (C): Every read gets the latest write (no stale data).

  • Availability (A): Every request receives a response (success/failure) — system never “goes dark.”

  • Partition Tolerance (P): The system continues to operate despite dropped or delayed messages between nodes.

CP vs AP: The Real-World Choices

✅ CP Systems (Consistency + Partition Tolerance)

  • Prioritize correctness of data over availability.

  • During partitions, the system may reject requests to avoid inconsistent results.

  • Think: "Better to be unavailable than wrong."

Examples:

  • Relational Databases (Postgres, MySQL clusters in strict mode)

  • Zookeeper / etcd (used in Kubernetes)

Use Cases:

  • Banking transactions (double debit prevention)

  • Metadata management (K8s configs, leader election)


✅ AP Systems (Availability + Partition Tolerance)

  • Prioritize serving requests even if data might be stale.

  • Eventual consistency is acceptable.

  • Think: "Better to be available than perfect."

Examples:

  • DynamoDB, Cassandra, Couchbase

  • DNS systems

Use Cases:

  • Social media feeds (a slightly stale feed is fine)

  • Shopping carts, recommendation engines


Why Not CA?

  • Partition tolerance (P) isn’t optional. Networks fail — cables break, packets drop, regions get isolated.

  • So in practice, CA systems don’t exist in large-scale distributed environments.


Choosing Between CP and AP

  • If data correctness is critical, lean CP.

  • If high availability is critical, lean AP.

  • Many modern systems blend these — offering tunable consistency (e.g., Cassandra’s QUORUM reads/writes).


CP vs AP Decision Path

Takeaway:

The CAP theorem isn’t about limitations.It’s about clarity of trade-offs.
Every distributed system makes a conscious choice between CP vs AP, depending on business needs.

As engineers, our job is to map system requirements to CAP trade-offs.

More from this blog

Node & Beyond

14 posts

Not just a blog. Definitely not clean code. Just me stumbling, learning, and sometimes celebrating small wins with Node.js and backend systems.