Skip to main content
cd ../lexicon
sys/docs/lexicon/consistent-prefix-reads.md
Lexicon

Consistent Prefix Reads

Difficulty: Advanced
3 min read
Definition
A consistency level guaranteeing readers only ever see writes in the order they truly happened on a partition, even though those reads may be arbitrarily stale.

Consistent Prefix Reads is a weaker-than-linearizable, stronger-than-eventual consistency model most commonly formalized in the context of geo-replicated multi-model databases such as Azure Cosmos DB and implicitly guaranteed within single-partition Spanner reads. The core invariant is order preservation without recency: a replica may lag behind the write-serving replica by an arbitrary amount, but it may never apply or expose writes W1, W2, W3 to a reader in an order other than W1, W2, W3. Crucially, this guarantee is typically scoped to a single partition or logical shard, because enforcing a global write-order across independently sharded partitions requires either a global sequencer, synchronized clocks with bounded uncertainty (as in TrueTime), or a Total Order Broadcast layer, all of which impose coordination costs the model is explicitly designed to avoid.

Under the hood, implementations typically rely on a monotonically increasing per-partition Log Sequence Number or epoch counter attached to every write. Replication streams (via WAL shipping, CDC, or an internal gossip-based log) apply entries strictly in LSN order on every replica, and read paths are constructed to never expose a gap: a replica serving reads must either block until it has applied entry N before serving entry N+1, or explicitly reject/redirect reads that would violate ordering. This differs fundamentally from plain eventual consistency, where replicas may apply writes out of order due to concurrent delivery paths, network reordering, or conflict resolution merges (e.g., in naive multi-master last-write-wins systems), producing reads that expose W3 before W2 was ever visible.

The primary architectural benefit is that Consistent Prefix Reads enable read-scaling across geographically distributed replicas without the latency penalty of quorum reads or leader-routing, while still preserving intuitive causal ordering for use cases like activity feeds, audit logs, or event timelines where users would be confused (or systems would misbehave) if updates appeared out of sequence. The tradeoff surface includes: replicas can be stale by seconds or more under network partition or replication lag; multi-partition transactions offer no cross-shard prefix guarantee unless an additional coordination protocol (e.g., a global commit timestamp combined with a Consistent Cut) is layered on top; and client-perceived staleness can vary per request if load balancers route reads to replicas at different replication offsets, producing non-monotonic reads across successive client requests unless session affinity or a session token (tracking the last-observed LSN) is also enforced.

The most common failure mode is conflating Consistent Prefix Reads with Read-Your-Writes or Monotonic Reads: a client can observe a strictly ordered but arbitrarily stale prefix of the write log and still fail to see its own most recent write, or worse, bounce between replicas at different offsets and appear to see writes, then not see them, then see them again, unless session stickiness or a bounded staleness token is explicitly layered on. Engineers building on this guarantee alone must therefore pair it with client-side session tokens or sticky routing when read-your-writes semantics are also required, and must treat cross-partition ordering as entirely unguaranteed unless the system explicitly documents a global sequencing mechanism.