Skip to content

NoSQL Databases - Wyatt's Notes

The CAP theorem, formalised by Gilbert and Lynch in 2002 based on Brewer’s 2000 conjecture, states That a distributed data store can provide at most two of three guarantees:

  • Consistency (C): every read receives the most recent write or an error
  • Availability (A): every request receives a non-error response (without guarantee about which data version)
  • Partition Tolerance (P): the system continues to operate despite arbitrary message loss or delay between nodes

Network partitions are not theoretical — they happen regularly in production. A switch fails, a DNS Update propagates slowly, a garbage collector pause causes a timeout, a cross-datacenter link Degrades. Any distributed system must tolerate partitions, which means the real choice is between CP and AP:

CategoryStrategyExample Systems
CPPreserve consistency, sacrifice availability during partitionsPostgreSQL (sync replicas), HBase, Redis (with replication)
APPreserve availability, sacrifice consistency during partitionsMongoDB (default, w:1), Cassandra, DynamoDB, CouchDB, Riak

The PACELC theorem (Abadi, 2012) extends CAP: when there is no partition (the EL part), the System must choose between Latency and Consistency:

\mathrm{PA \to \mathrm{EL : \mathrm{when no partition, prefer availability and latency over consistency

\mathrm{PC \to \mathrm{EC : \mathrm{when no partition, prefer consistency, accepting higher latency

This captures a nuance that CAP misses: even during normal operation (no partition), systems make Consistency-latency trade-offs. DynamoDB defaults to eventual consistency for low latency but can be Configured for strong consistency (higher latency). Cassandra defaults to eventual consistency but Supports tunable consistency per operation.

Consistency is not binary. There is a spectrum of consistency models, from strongest to weakest:

ModelGuaranteeExamples
LinearizableOperations appear to execute atomically and in real-time orderSingle-node databases, ZooKeeper
SequentialOperations appear in some total order consistent with real timeGoogle Spanner (external consistency)
SerializableEquivalent to some serial execution of transactionsPostgreSQL SERIALIZABLE
Snapshot IsolationEach transaction reads from a consistent snapshotPostgreSQL REPEATABLE READ
CausalCausally related operations are seen by all nodes in orderDynamoDB (with consistent reads)
Read-your-writesA reader always sees its own writesMost systems with sticky sessions
SessionConsistency within a single client sessionMongoDB (read preference)
EventualIf no new writes, all reads eventually converge to the same valueCassandra, CouchDB, DynamoDB (default)