CAP, PACELC and Consistency Models

Reason about the trade-offs between consistency, availability and latency in distributed data systems.

Advanced · about 3 hours · difficulty 4/5

Learn first: Replication, Read Replicas and Failover

Once data lives on more than one machine, you must decide what happens when machines disagree or cannot talk to each other.

CAP in plain words

The CAP theorem says that during a network partition a distributed system must choose between consistency (every read sees the latest write) and availability (every request gets a non-error answer). Since partitions will happen, the real question is what your system does when they do: refuse some requests, or answer with possibly stale data.

PACELC

PACELC extends CAP: if there is a Partition choose A or C, Else (normal operation) choose between Latency and Consistency. This is the trade-off you feel every day: synchronous replication is consistent but slower; asynchronous is fast but can serve stale reads.

Consistency models, strongest to weakest

  • Linearizable (strong): behaves like a single copy; after a write completes, everyone sees it.
  • Sequential / causal: operations appear in an order that respects cause and effect.
  • Read-your-writes, monotonic reads: per-session guarantees that avoid the most confusing user experiences.
  • Eventual consistency: replicas converge if writes stop, but reads may be stale for a while.

Applying it

  • Bank balances, inventory reservations and unique usernames usually need strong consistency.
  • Like counts, view counts and feeds are fine with eventual consistency.

Pick per feature, not per company. Also note that "ACID consistency" (constraints hold) and "CAP consistency" (linearizability) are different ideas that share a word.

You are ready to move on when you can classify features of a real app by the consistency they need and explain what a user would see if you chose wrong.

Key concepts

  • CAP theorem
  • Network partitions
  • PACELC
  • Strong vs eventual consistency
  • Session guarantees
  • Quorums
  • Consensus (Raft, Paxos)

Mini project

Write a short design note for a ticket-booking app deciding which operations need strong consistency and which can be eventual, with the failure scenario for each.

Check yourself

Why is 'we picked CA' not a meaningful choice for a system that runs across multiple data centers?

Free resources