Notesreplication๐ŸŒฑ seedling

Consistent Prefix Reads

Also: Consistent Prefix

If writes happen in some order, readers see them in that order: a prefix of history, never history with gaps. It breaks when causally related writes live in different partitions.

Why it exists

A question lands on one partition and its answer on another. Each partition replicates independently, so an observer can see the answer before the question.

How it works

  • In one leader-based database a single log orders every write, so it comes for free.
  • In a partitioned database each partition has its own log; there's no global order across them.
  • Fixes: put causally related writes in the same partition (a whole chat thread on one shard), or track causal dependencies (Happens-Before) and delay visibility until dependencies are visible.

Trade-offs

Option Cost
co-locate related writes constrains partitioning; hot spots
track causal dependencies metadata on every write; delayed visibility

In practice

  • Chat and comment systems key messages by conversation so one partition's log orders a thread.

Pitfalls

  • Assuming per-partition ordering implies global ordering.

Recall

These cards are also in your review deck, scheduled with spaced repetition.