Consistency Models

What "consistent" actually means, what each level costs, and how to pick one from a product requirement.

CAP PACELC Linearizable Causal ACID vs BASE
โš–๏ธ

The CAP Theorem

CAP names three properties a distributed store might want: Consistency (every read sees the most recent write, as if there were one copy), Availability (every request gets a non-error response), and Partition tolerance (the system keeps working when the network drops messages between nodes).

The popular framing, "pick two of three," is wrong. Partitions are not a choice you make; networks fail whether you like it or not. So P is not optional for any real distributed system. The theorem is really about one moment: when a partition happens, do you sacrifice consistency or availability?

   Client writes x=2                                   Client reads x
          โ”‚                                                   โ”‚
          โ–ผ                                                   โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ•ณ  partition  โ•ณ         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚    Node A     โ”‚ โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ X โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ โ”‚    Node B     โ”‚
   โ”‚  accepts x=2  โ”‚          (cannot sync)          โ”‚  still x = 1  โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

   CP choice โ†’ Node B refuses the read (or A refuses the write): no stale data, but unavailable.
   AP choice โ†’ Node B returns x=1: available, but the read is stale until the partition heals.
CP โ€” consistency over availability Refuse rather than lie

During a partition, reject requests the system can't serve correctly. The minority side stops taking writes; some clients get errors.

Fits: anything where a wrong answer is worse than no answer โ€” balances, inventory, locks, config, leader election.

Examples: ZooKeeper, etcd, HBase, Spanner.

AP โ€” availability over consistency Answer, reconcile later

During a partition, keep serving from whatever node you can reach. Reads may be stale, writes may conflict, and the system reconciles once the partition heals.

Fits: anything where a slightly stale answer is fine โ€” feeds, likes, product catalogs, view counts.

Examples: Cassandra, DynamoDB, Riak.

โš ๏ธ
Two traps. First, "CA" systems don't exist in the distributed sense โ€” drop P and you just have a single node. Second, CAP's C means linearizability, not the C in ACID; they're unrelated letters that happen to share a word.
๐Ÿ”€

PACELC: The Part CAP Leaves Out

CAP only speaks about the partition case, which is rare. PACELC finishes the sentence: if there is a Partition, choose Availability or Consistency; Else, in normal operation, choose Latency or Consistency.

That "else" is the honest part. Any system that replicates data faces a choice on every write: wait for replicas to acknowledge before returning (consistent, slower) or return as soon as one node has it (fast, possibly stale). You pay this tax all day, not just during the once-a-quarter partition.

Reading the four-letter labels Classification
SystemPACELCMeaning
Cassandra, DynamoPA / ELStay available in a partition; favor latency otherwise. Tunable, but this is the default posture.
SpannerPC / ECConsistency always, even at the cost of latency. Pays with synchronized-clock waits.
Single-node RDBMSโ€” / ECNo partition story; strongly consistent because there's one copy.
MongoDB (default)PA / ECAvailable under partition; consistent reads from the primary in normal operation.
๐Ÿ’ก
PACELC is the more useful lens in an interview because it forces you to talk about the common case. Saying "in normal operation I'll trade a little latency for read-your-writes here, but go EL for the like counter" shows you understand the cost is continuous, not a partition-only event (Tradeoffs).
๐Ÿ“ถ

The Consistency Spectrum

"Consistent" is not one thing. It's a ladder, and each rung down buys lower latency and higher availability by allowing one more kind of anomaly. Know the rungs and one concrete anomaly each, because that anomaly is how you explain the level to an interviewer.

  STRONGER โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ WEAKER
  more coordination ยท higher latency          less coordination ยท lower latency

   Linearizable  โ”€โ”€โ–ถ  Sequential  โ”€โ”€โ–ถ   Causal    โ”€โ”€โ–ถ   Eventual
   single-copy        global order       cause-before      replicas
   illusion,          but no real-time    -effect only,     converge if
   no stale reads     ordering            concurrent free   writes stop
Each rung and the anomaly it does or doesn't allow One example each
LevelGuaranteeAnomaly at this level
LinearizableEvery read returns the latest write; the system acts like one copy on a single timeline.None. This is the gold standard, and the most expensive.
SequentialAll nodes agree on one order of operations, respecting each client's own order.Two users may disagree on real-time timing: your write "happened first" on the clock but is ordered after mine.
CausalOperations that are causally related are seen in order everywhere; unrelated ones may differ.Concurrent writes can appear in different orders on different replicas โ€” but you never see a reply before the comment it answers.
EventualIf writes stop, all replicas converge to the same value. That's the only promise.Read-your-writes violation: you post a comment, refresh, and it's gone because you hit a lagging replica.
โ„น๏ธ
The gap between linearizable and everything else is the one that matters most in practice. Linearizability needs coordination on the write path โ€” a consensus round or a single leader (Consensus) โ€” which is exactly the latency PACELC warned about. Everything below it trades that coordination away.
๐ŸŽซ

Session Guarantees

Full linearizability is often overkill. What users actually notice is inconsistency within their own session: they post something and it vanishes, or a page refresh shows older data than the last one. Session guarantees fix exactly those, and they're cheap because they only constrain one client's view, not the whole cluster.

The four that carry most products Per-session
GuaranteePromiseBug it prevents
Read-your-writesYou always see your own updates.Comment disappears right after you post it.
Monotonic readsOnce you've seen a value, you won't later see an older one.Timeline jumps backward on refresh.
Monotonic writesYour writes apply in the order you issued them.Second edit lost behind the first.
Writes-follow-readsA write you make is ordered after the read it was based on.Reply appears before the post it answers.
๐Ÿ’ก
These are usually implemented by pinning a session to one replica (sticky routing) or by tracking the version a client has seen and refusing to serve older ones. On an eventually-consistent store, layering read-your-writes on top is often all a social product needs. Reach for that before you reach for global strong consistency (Replication).
๐Ÿงช

ACID vs BASE

ACID Transactional
  • Atomicity โ€” all of a transaction happens, or none of it.
  • Consistency โ€” a transaction moves the DB from one valid state to another, preserving invariants.
  • Isolation โ€” concurrent transactions don't see each other's partial work.
  • Durability โ€” once committed, it survives a crash.

Cheap and natural on a single node. The classic home of relational databases.

BASE Available
  • Basically Available โ€” the system answers, even if degraded.
  • Soft state โ€” data may change without input as replicas sync.
  • Eventual consistency โ€” replicas converge over time.

The design philosophy of AP systems: give up strict guarantees to stay up and stay fast at scale.

โš ๏ธ
ACID within one node is easy; stretching it across nodes is where the cost hides. Multi-record, multi-service atomicity needs two-phase commit or sagas, and that machinery is a whole topic of its own (Distributed Transactions). And again: ACID's "C" (invariants) is not CAP's "C" (linearizability).
๐ŸŽฏ

Choosing in an Interview

The move is not to pick one consistency level for the whole system. It's to look at each piece of data and ask what a wrong or stale answer costs. Most real designs mix levels: strong where money and identity live, eventual for the derived views that dominate traffic.

Product requirement โ†’ model Mapping
RequirementModelWhy
Payments, balances, inventory, seatsStrong / linearizableDouble-spend or overselling is unacceptable; correctness beats latency.
Usernames, locks, leader electionStrong / linearizable"Exactly one" must be true across the cluster.
Comment threads, collaborative editingCausalCause-and-effect order must hold; concurrent edits can be reconciled.
Your own posts and profile editsSession (read-your-writes)Users must see their own actions; others can lag briefly.
Feeds, likes, view counts, catalogsEventualRead-heavy, tolerant of staleness; availability and latency win.
๐Ÿ’ก
When the interviewer asks "how consistent does this need to be?", the strong answer is never "strongly consistent everywhere." It's "the order-of-record is strongly consistent; the timeline and counters are eventual with read-your-writes for the author." Naming the split is the senior signal (Design Process).
๐Ÿ“‹

Quick Reference

Model Guarantee Example system Anomaly avoided
LinearizableReads see the latest write, single-copy illusionetcd, ZooKeeper, SpannerStale reads, lost order
SequentialOne global order respecting per-client orderDistributed logsReordered per-client ops
CausalCause precedes effect everywhereMongoDB causal sessionsReply before its comment
Read-your-writesYou see your own updatesSession layer on eventual storeYour write vanishing
EventualReplicas converge if writes stopCassandra, DynamoDB, DNSOnly guarantees convergence
โ„น๏ธ
The one-liners to keep ready. CAP: partitions force a choice between consistency and availability. PACELC: even without partitions, replication trades latency against consistency. The move: match each piece of data to the weakest model that still hides the anomaly users would notice.