Consistency
Models
When user A updates their profile, when does user B see it? Immediately? In 5 seconds? Never? This "when" is the consistency model.
Strong Consistency
Linearizability
The system behaves as if there is only one copy of the data and all operations are atomic.
User A writes X = 5. Success.
User B reads X. MUST see 5.
High latency (must replicate to all nodes before returning success). Low availability (if one node is down, write might fail).
Eventual Consistency
"Ideally, eventually."
If no new updates are made to a given data item, eventually all accesses to that item will return the last updated value.
User A writes X = 5 to Node 1.
User B reads X from Node 2. Might see 4 (old).
100ms later... Node 1 syncs to Node 2.
User B reads X. Now sees 5.
Extremely fast writes (return immediately). High availability. Standard for DNS, Social Feeds, Comments.
Causal Consistency
A middle ground. Operations that are causally related must be seen by everyone in the same order. Unrelated operations can be seen in any order.
The Chat Example
Charlie might see Bob's reply BEFORE Alice's message.
"Whatever..." → "I am breaking up..."
(Makes no sense)
Guarantees that if B depends on A, everyone sees A before B.
Linearizability vs Serializability
Linearizability
Single Object
Guarantee about a single register (key-value pair). Reads return the absolute latest write.
"Freshness guarantee."
Serializability
Multiple Objects (Transactions)
Guarantee about transactions (groups of operations). Execution ensures the same result as if transactions ran one after another.
"Isolation guarantee."
Strict Serializability = Linearizability + Serializability. (The holy grail, very expensive).
Quorums (R + W > N)
How to configure Consistency?
In systems like Cassandra/Dynamo, you choose your consistency level per request.
- N = Total replicas (e.g., 3)
- W = Write quorum (nodes that must confirm write)
- R = Read quorum (nodes that must confirm read)
(Ensures read and write sets overlap by at least one node)
Configurations
Write to all, read from any one.
Write to one, read from all (to find latest).
Usually (N/2 + 1). E.g., N=3, W=2, R=2.