Client-centric consistency models
Client-centric consistency models describe guarantees about the behaviour observed by a single client (session) when reading and writing replicated data in a distributed system, focusing on session guarantees such as monotonic reads and read-your-writes.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Client-centric consistency models matter when an engineer builds or uses a replicated system where different copies (replicas) of data may be updated and read from different servers. These models give guarantees from a single client's viewpoint (a session) so the system feels usable and predictable even if full global consistency (linearizability) is too expensive.
Key ideas
Start with definitions of the basic terms (plain English):
- Replica: A copy of a data item stored on a server. Each replica can be independently read or updated.
- Client: A process (user or program) that issues read and write operations to replicas.
- Session: A sequence of operations by a single client, ordered by that client's local time or program order. A session defines the client-centric viewpoint.
- Version: A particular state of a data item produced by a write. Versions are often identified by timestamps, sequence numbers, or vector clocks.
- Eventual consistency: The system guarantees that if no new updates are made, all replicas will converge to the same value eventually. (This is a weak, data-centric guarantee.)
Client-centric models focus on how a single session should observe reads and writes. The classic formalisation (Terry et al.) gives four standard session guarantees; define each exactly and state assumptions and consequences.
- Monotonic Reads (MR)
- Definition: For a given client session, if the client has seen a version v of an object, then any later read in the same session must not return a version older than v.
- Formal claim (informal): If a session reads version v at time t1, then for any later read at t2 > t1, the returned version v' must satisfy v' >= v according to the version ordering used by the system.
- Assumptions: versions have a well-defined order for a given object (e.g., total with sequence numbers/timestamps or partial with vector clocks), and the client can track the highest version (per that order) it has seen.
- Consequence: prevents the client from observing time-travel to older states.
- Diagram to draw for exams: draw a client C with two arrows to replicas R1 at t1 and R2 at t2. Label version at R1 as v2 and at R2 as v1 (v1 < v2). Show that MR is violated if C reads v2 at t1 from R1 then reads v1 at t2 from R2.
- Monotonic Writes (MW)
- Definition: If a client issues write w1 followed later by write w2 in the same session, then w1 must be applied (made visible) before w2 at every replica.
- Formal claim: For writes w1, w2 from same session with program order w1 -> w2, the system must ensure that for every replica r, visibility_time(w1, r) <= visibility_time(w2, r).
- Assumptions: the system can order or tag writes from a client and ensure propagation ordering (e.g., via sequence numbers per session).
- Consequence: preserves the program order of a client's writes across the system; prevents later writes from becoming visible before earlier ones.
- Diagram to draw: client C issues w1 then w2 to different replicas; show arrows from client to replicas and label times; show MW is violated if some replica applies w2 before w1.
- Read Your Writes (RYW)
- Definition: After a client performs a write w and receives acknowledgement, a subsequent read in that client session must return a value that reflects w (or a later write), not a state that ignores w.
- Formal claim: If client performs write w producing version v at time t1, then any read by same client at t2 > t1 must return version v' with v' >= v.
- Assumptions: the client knows the fact that it wrote v (acknowledgement), and the system can route reads or check versions to return at least v.
- Consequence: ensures a client immediately observes its own updates.
- Implementation notes (brief): RYW can be implemented by sticky sessions (always contacting the same replica) or by carrying a write-timestamp with the client and ensuring reads return >= that timestamp.
- Writes Follow Reads (WFR)
- Definition: If a client reads a version v of an object and then issues a write w (possibly to a different object), then w must be applied after the write that produced v at all replicas.
- Formal claim: For read r that returns version v (possibly read from replica r1) and later write w from the same session, the system ensures for all replicas r: visibility_time(v, r) <= visibility_time(w, r).
- Assumptions: the session tracks dependencies introduced by reads and enforces them when it writes.
- Consequence: the write depends on the read and must not overwrite or be applied as if the read never occurred; preserves causal dependence from read to subsequent writes.
Notes on relationships and strengths:
- These four guarantees are client-centric; they do not enforce a global order across clients. They are weaker than strong data-centric models (like linearizability) but stronger than bare eventual consistency for a client's experience. Causal consistency implies all four session guarantees; providing all four as session guarantees does not by itself enforce full causal consistency across clients.
- A system may provide any subset of these guarantees. For example, many geo-replicated stores give RYW and MR but not MW or WFR by default.
- Implementation techniques: sticky sessions, client-held metadata (last-seen version or vector clock), per-session sequence numbers, read-repair or read-from-quorum to ensure visibility, and middleware routing.
Exact statements to remember for exams: "Monotonic Reads: later reads must not return older versions than earlier reads in the same client session." Repeat similarly for the other three.
Formulas
V_replica(obj) = version number of object on replica; unitless — used when versions are simple sequence numbers.
V_client_last(obj) = highest version number of object seen by client in session; unitless — used to enforce MR and RYW.
V_replica(obj) >= V_client_last(obj) means the replica is sufficiently up-to-date for a client read — applies when checking monotonic reads or read-your-writes. If versions are vector clocks, interpret '>=' as component-wise dominance (for all i, V_replica[i] >= V_client_last[i]); with scalar timestamps or sequence numbers, use the usual numeric order.
TS(w) = timestamp or sequence number assigned to write w; unitless — used for ordering writes in MW.
TS(w1) < TS(w2) if w1 was issued before w2 in same session (per-client sequence); holds if client increments sequence number per write.
VV[i] = component i of a vector clock; dimensionless — used to capture causal dependencies when vector clocks are used.
(Each symbol is dimensionless; these are ordering tokens, not physical quantities.)
Worked examples
Example 1 — Monotonic Reads violation and fix (step-by-step): Given: Two replicas R1 and R2 of object X. Versions: at time t1, R1 has X:v2, R2 has X:v1 (v1 < v2). Client C reads X from R1 then later from R2. Steps:
- At t1 client C -> R1: read X. R1 returns v2. (Client records V_client_last(X) = v2.)
- Client moves to a different network partition; at t2 reads from R2. R2 returns v1 because it hasn't received v2 yet.
- Violation: t2 read returned v1 < v2, breaking MR.
Fix (sticky session): ensure client's subsequent reads go to R1 until R2 catches up, or use metadata: client sends V_client_last(X)=v2 with read; replica compares its V_replica(X) and if V_replica < V_client_last then replica either delays response or forwards read to an up-to-date node.
Final: With check
V_replica >= V_client_lastenforced, MR holds.
Example 2 — Read-Your-Writes with timestamps (algorithm trace): Given: Client C writes W1 producing TS(W1)=5 to replica R1 and gets ack. Later C reads same object from R2. Steps:
- After write, client stores lastWriteTS = 5.
- For next read, client sends lastWriteTS=5 to R2.
- R2 compares its local version timestamp for the object to 5. If that timestamp >= 5, return local value; else forward the read or delay until it has a version >= 5 (or read from a quorum).
- This ensures RYW: the client will not observe a state older than its own write.
Example 3 — Monotonic Writes enforcement with per-session sequence numbers (short trace): Given: Client issues w1 then w2. Assign per-client sequence numbers s1=1, s2=2. Steps:
- Client sends w1 with clientID and seq=1. Replicas apply w1 when receiving seq=1.
- Client sends w2 with seq=2. Replicas apply w2 only after seq=1 has been applied. If they receive seq=2 early, they buffer w2 until seq=1 arrives.
- This guarantees MW: seq enforces per-session order at each replica.
Common mistakes
- Forgetting to specify the ordering metric (timestamps or sequence numbers) when giving formal statements — statements must refer to a version/order relation.
- Ignoring how metadata (timestamps, sequence numbers, vector clocks) is carried and compared — the mechanism matters for correctness.
- Assuming eventual consistency implies immediacy of convergence; eventual only guarantees convergence if updates stop.
For your exam
Types of questions you will see:
- Definitions: Define Monotonic Reads / Read-Your-Writes etc. Full-marks: state the definition precisely, give assumptions and an example or counter-example.
- Short notes: Compare the four session guarantees. Full-marks: describe each guarantee, show relations and give two implementation techniques.
- Derivations/Proofs: Prove that a simple algorithm (per-session sequence numbers or vector clocks) enforces a guarantee. Full-marks: state invariants, show that invariant is preserved by each operation, and show it implies the guarantee.
- Diagrams: Draw client and replicas showing a violation. Full-marks: clear labels (client, replicas, times, versions), arrows for operations, and explanation of why guarantee held or violated.
- Algorithms/programs: Write pseudocode for client carrying last-seen-version and replica checks for reads. Full-marks: correct metadata updates on read and write, handling of stale replica (forward/delay/buffer), and discussion of trade-offs (latency vs freshness).
What to include for full credit: precise definition, assumptions (what metadata exists, how replicas communicate), a clear example (numbers/versions), and explanation of how to enforce the guarantee.
Quick check
- What does Read-Your-Writes (RYW) require a system to guarantee for a client session?
- How does Monotonic Writes (MW) differ from Writes Follow Reads (WFR)?
- Give one simple implementation technique to enforce Monotonic Reads.
Answers: 1) After a client writes and gets acknowledgement, later reads in that session must reflect that write or a later one. 2) MW preserves program order among the client's writes; WFR orders a write after the versions the client previously read (a read->write dependency). 3) Sticky sessions (route the session to the same replica) or carry last-seen-version with client and block/forward reads until replica reaches that version.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?