← Lessons

quiz vs the machine

Gold1440

System Design

Consistent Prefix Reads

Ensuring causally related writes are never observed out of their original order.

4 min read · core · beat Gold to climb

The out of order anomaly

Suppose one user asks a question and another answers it. If a third observer reads from replicas that applied the answer before the question, the conversation appears nonsensical: an answer to a question that has not been asked yet.

Consistent prefix reads guarantee that if a sequence of writes happens in a certain order, anyone reading them sees them in that same order, never with later writes appearing before earlier causally related ones.

Why partitioning breaks it

In a single partition, writes already have a total order, so the problem rarely appears. Trouble comes with sharding: the question and answer may live on different partitions that replicate at different speeds, so an observer can see one without the other.

How to provide it

  • Keep causally related writes in the same partition when possible.
  • Or track causal dependencies explicitly so a reader waits for the prerequisite write before showing the dependent one.

Key idea

Consistent prefix reads keep causally ordered writes from being observed out of order, a problem that sharding makes real.

Check yourself

Answer to earn rating on the learn ladder.

1. What does consistent prefix reads guarantee?

2. Why does sharding make this anomaly more likely?