Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

A question-and-answer app stores questions and answers in different partitions of a replicated store, and each partition replicates with its own lag. Readers sometimes see an answer before the question it answers.

What is the consistent prefix reads guarantee, why do partitioned stores break it, and how do designs restore it?

Consistent prefix reads means that if writes happen in a certain order, every reader sees them in that order: never a later write without an earlier one it depends on. Partitioned stores break it because each partition replicates independently, so the answer's partition can become visible on a replica before the question's partition, even though the question was written first. Designs restore it by keeping causally related writes in one partition, such as keying both by thread id so one log orders them, or by tracking dependencies so an answer is held back until its question is visible, which is causal consistency.

Why this question is asked

Seeing an answer before its question is a small glitch on a forum, but the same anomaly in other systems means a payment before its order, or a reply to a message that has not arrived. Interviewers ask about consistent prefix reads to see whether we know the weaker consistency guarantees by name and understand where each one comes from. In this answer, we will define the guarantee, show why partitioning breaks it, see why a single-leader unpartitioned database does not have the problem, and look at the two ways to restore it.

1What Consistent Prefix Reads Promises

Imagine all writes in a system as a sequence: question Q is written, then answer A that refers to Q. A reader who looks at the system at any moment sees some state. Consistent prefix reads promises that this state is always a prefix of the sequence: maybe nothing, maybe Q, maybe Q and A, but never A without Q. In other words, readers may be behind, but they never see the effects of writes out of order.

It is a weak guarantee: it says nothing about how far behind a reader is, or whether a user sees their own writes. But it rules out a specific kind of nonsense, effects without their causes, which users find much more confusing than mere delay.

2Why Partitioned Stores Break It

In this app, questions and answers are stored in different partitions, perhaps because questions are keyed by question id and answers by answer id. Each partition has its own leader and its own replicas, and each replicates with its own lag. Suppose the question's partition is busy and its replica is 300 milliseconds behind, while the answer's partition replica is 20 milliseconds behind. A reader who queries replicas 100 milliseconds after both writes sees the answer, because its partition has caught up, but not the question.

Step throughAnswer visible before its question
WriterQuestions partitionAnswers partitionReader
write question Q
write answer A (refers to Q)
replica applies A after 20 ms
read thread at 100 ms
A is there
read question
Q not yet replicated
replica applies Q after 300 ms

8 messages in order. Play them, or step through them one at a time.

Each partition is internally ordered; nothing orders writes across them.

Notice that nothing is wrong with either partition. Each one, on its own, shows its writes in order. The problem is that there is no global order across partitions: the store never recorded that A depends on Q, so it has no reason to hold A back.

3Why a Single Leader Without Partitions Does Not Have the Problem

In a single-leader database that is not partitioned, such as one PostgreSQL primary with replicas, all writes go through one log. The primary assigns every commit a position in that log, and each replica applies the log in exactly that order. A replica may be behind, but whatever point it has reached is a prefix of the primary's history, so if it shows A, it already shows Q.

The anomaly therefore appears as soon as there is more than one independent log: a partitioned or sharded store, multi-leader replication, or read models built by independent consumers, for example two Kafka consumers each maintaining one table in a search index. Any of these can expose a later write before an earlier one.

4Fix 1: Keep Related Writes in One Partition

The simplest fix is to make sure writes that depend on each other share a log. If both questions and answers are keyed by thread id, a question and its answers land in the same partition, and that partition's single log orders them.

Java
// Before: different keys, different partitions
producer.send(new ProducerRecord<>("qa", question.id(), question)); // key q-881 -> partition 3
producer.send(new ProducerRecord<>("qa", answer.id(), answer)); // key a-5512 -> partition 9
// After: both keyed by thread id, one partition, one order
producer.send(new ProducerRecord<>("qa", question.threadId(), question)); // key t-77 -> partition 5
producer.send(new ProducerRecord<>("qa", answer.threadId(), answer)); // key t-77 -> partition 5, after Q

The same idea applies to a database: if questions and answers share the partition key thread_id, they are stored and replicated together. The cost is that partitioning now follows threads, so a very busy thread becomes a hot partition, and queries that span threads, such as all answers by one user, need a secondary index or a separate read model.

5Fix 2: Track Dependencies

When related data cannot live in one partition, we can record the dependency explicitly. The answer carries the id and version of the question it refers to. A reader, or a layer in front of the store, checks whether that question is visible on the replica it is reading from, and if not, either waits briefly, reads the question from its leader, or hides the answer until the question arrives.

Done systematically, this is causal consistency: every write carries the set of writes it depends on, and a write is made visible only after its dependencies are. Some stores implement it with version vectors or hybrid logical clocks; in application code, carrying the parent's id and version is usually enough. The cost is metadata on every write and occasional waiting, but it scales across partitions.

6Follow-up questions

How is consistent prefix different from read-your-writes?

Read-your-writes is about a user seeing their own writes. Consistent prefix is about any reader seeing writes in order. A user could see their own answer immediately and still see it before the question, so the two guarantees are independent.

Does Kafka guarantee consistent prefix?

Within one partition, yes: consumers read records in log order. Across partitions there is no order, so a consumer can process a record from partition 9 before an earlier one from partition 3. That is why related events share a key.

Is causal consistency expensive?

It is much cheaper than strong consistency because it needs no global coordination, only dependency metadata and the occasional short wait. It is the strongest guarantee that stays available during network partitions.

7Conclusion

In this answer, we saw that consistent prefix reads means readers see writes in the order they happened, never an effect without its cause. Partitioned stores break it because each partition replicates on its own schedule, so an answer can become visible before its question, while a single-leader, unpartitioned database replays one log in commit order and keeps it. We restore it by putting causally related writes in one partition, keyed by thread, or by carrying dependencies so a write is shown only after the writes it depends on, which is causal consistency.

What to say in the interviewAbout 90 seconds aloud

Open with

Consistent prefix reads means that if a sequence of writes happens in some order, any reader sees them in that order. A reader can be behind, but never sees a later write without an earlier one it depends on, so never an answer without its question.

Then, if they want more

A partitioned store breaks this because each partition has its own log and replicates with its own lag. If questions and answers are in different partitions, the answer's partition may be 20 milliseconds behind and the question's 300 milliseconds behind, and a reader in between sees the answer first, even though the question was written first.

Each partition is ordered internally; nothing orders writes across partitions. A single-leader unpartitioned database does not have this problem, since every replica applies one log in commit order, so whatever a replica shows is a prefix of history. The problem appears with partitioning, multi-leader replication, and read models built by independent consumers. There are two ways to restore it.

The first is to keep causally related writes in one partition, for example key both questions and answers by thread id, so one log orders them; the cost is that a busy thread becomes a hot partition.

The second is to track dependencies: the answer carries the question's id and version, and the reader holds the answer back, or fetches the question from the leader, until the question is visible. Done systematically, that is causal consistency.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is the consistent prefix reads guarantee, why do partitioned stores break it, and...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/b20d40ee8e/