CAP & consistency models

Linearizability vs eventual consistency, read-your-writes, quorum math (R + W > N). Know what your favorite database actually gives you by default.

About 25 min read3-question knowledge check

The mental model

Imagine a bank with two branches, Mumbai and Delhi, connected by a phone line. Both hold a copy of your balance. The line goes dead. A customer walks into Mumbai and asks to withdraw money. The branch manager has exactly two options and no third one: serve the withdrawal using the possibly-stale local copy, or refuse to serve until the line is back. Serving risks two branches handing out the same rupees. Refusing means a healthy branch turned away a real customer.

That is CAP, in full. It is not "pick two of three". The partition is not a choice you make — networks drop packets, switches fail, a cloud AZ link degrades — so P is a condition, not an option. CAP says: when a partition happens, a system either sacrifices consistency (answer with maybe-stale data) or availability (refuse to answer). When there is no partition, you can have both.

The reason this exists as a named theorem is that engineers kept designing distributed systems as if they were one big single machine, then getting paged when reality disagreed. Without this vocabulary you end up with a design doc that says "the database is replicated for high availability" and an incident report that says "a user saw their own write disappear" — and no one can connect the two sentences. The vocabulary is the point: linearizable, eventual, read-your-writes, quorum, replication lag. These words let you write down, before launch, exactly which anomaly your users will see and how bad it is.

The second idea that matters more in practice than CAP itself: PACELC. If there is a Partition, choose Availability or Consistency; Else (the 99.9% of the time the network is fine), choose Latency or Consistency. Strong consistency is not free during normal operation either — it costs a cross-node round trip on every write, or a read that must go to the leader. Most real design arguments are the "else" half, not the partition half.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision