Unit 4 of 14 · about 4 hours · explain, implement

Stale reads, read-your-writes and monotonic read and write guarantees

The Systems unit on consistency models and conflict resolution classified session histories. Here the new work is the eligibility test, including what happens when no reachable replica contains the session's dependencies.

You'll be able to

  • Separate read-your-writes, monotonic reads, monotonic writes and writes-follow-reads using histories.
  • Implement a session frontier that routes or waits for a sufficiently advanced replica.
  • Diagnose a session violation after rerouting or losing client context.

Covers

Stale reads and monotonicityRead-your-writes session guaranteesMonotonic reads and writes
1

Read

In this order, only the parts listed

0 of 2 done

  1. DDIA, 2nd edition: replica routing for sessionsDDIA 2e - Chapter 6 Replication and Chapter 10 Consistency Sections

    Chapter 6, Replication: Problems with Replication Lag through Solutions for Replication Lag, pp. 209 to 215

    Use the familiar stale-read examples as routing tests, not a second introduction. Stop before Multi-Leader Replication.

  2. Terry et al. (1994): session contracts and enforcementSession Guarantees for Weakly Consistent Replicated Data (Terry et al., 1994)

    Sections 3.1 to 3.4, the four guarantees; Section 4, Providing the guarantees; Section 5, Practical implementation of the guarantees, including Figure 1

2

Focus on

  • Read-your-writes requires a read view that includes the session's prior writes, not necessarily their unchanged values after other writes supersede them.
  • Monotonic reads tracks previously observed history. Monotonic writes orders the session's writes at replicas; writes-follow-reads carries dependencies from reads into later writes.
  • Use an applied log position for a single ordered lineage or a dependency vector for multiple origins. A frontier must describe a complete prefix, not merely the largest event observed.
  • The paper's enforcement relies on ordered propagation and session metadata. If no eligible replica is reachable, preserve the guarantee by waiting or failing rather than silently using a stale one.
Common mistakes · 3
  • Using sticky routing as a complete guarantee when the chosen replica can restart, roll back or be replaced.
  • Comparing returned numeric values to test monotonic reads. A later legitimate write may lower the value.
  • Confusing the order in which the client sends writes with the order in which every replica exposes them.
3

Try it yourself

Closed-book, before checking anything

In a Python 3 model of one log lineage, implement a session token storing the greatest required applied position. After the session writes at position 4, offer replicas applied through positions 2 and 5: only the second is eligible for a read-your-writes read. After reading through position 5, reject the first replica for monotonic reads even if the session made no new write. For monotonic writes, delay a second write at a new replica until its first write is included. Preserve the token across rerouting, then erase it deliberately and retain the violating trace.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Can a session satisfy monotonic reads while always reading stale data?Answer

    Yes. Its observed histories must not move backward, but they need not be globally current.

  2. 2.Does read-your-writes alone require a replica serving a later write to include all earlier reads?Answer

    No. Writes-follow-reads carries those read dependencies into the write. Read-your-writes constrains subsequent reads relative to the session's writes.

  3. 3.Why can satisfying a session guarantee reduce availability after a partition?Answer

    The reachable replicas may lack the required history. Serving them immediately would violate the guarantee, so the operation must wait, fail, or reach an eligible replica.

  4. 4.Does a write on a phone automatically enter the browser's session token?Answer

    No. Cross-device guarantees need a shared or transferred session context. A common user name alone does not transfer dependencies.

5

Practice

  • AlgoMaster: Route Session-Consistent Replica Reads

    recordWrite, advanceReplica and routeRead: a replica is eligible for read-your-writes only when its applied LSN reaches the session's greatest write LSN, with the primary as the fallback

    Premium, on a subscription the learner owns. The judge falls back to the primary; your loglab router should also offer waiting or failing, and add monotonic reads and context loss on rerouting.

  • AlgoMaster: Validate Session Consistency

    isConsistent over one session history of per-key versioned reads and writes, checking read-your-writes and monotonic reads

    A free warm-up. It tracks a per-key high-water version, not a log prefix, so it cannot express monotonic writes or writes-follow-reads.

You're done when

Your session tests reject an ineligible replica after both a write and a read, and distinguish monotonic-write ordering from read-your-writes visibility.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 14 more in the section

Also in this section