Part 4 of 5 · 2 min read
Consistent prefix reads
Without this guarantee, causally related writes can appear out of order to a reader.
Consistent prefix reads
Think of overhearing the second half of a phone conversation before the first half. Some delay scrambled the order the two halves arrived in, making the conversation sound nonsensical even though it happened in a perfectly sensible order.
In plain words: consistent prefix reads guarantees that if one write happened before another, in a way that is causally related, such as a question being asked before its answer, any reader who sees both writes sees them in that same order, never the answer before the question. This specifically matters when writes to different pieces of data can replicate at different speeds, risking a reader seeing a later, causally dependent write before the earlier write it actually depended on.
A worked example. A chat application logs "What time is the meeting?" as one write and "3pm" as a reply write moments later; without consistent prefix reads, a reader could see the reply "3pm" appear before the question it was answering ever shows up, due to the two messages replicating to that reader's follower at different speeds.
The key lines. No new SQL; consistent prefix reads is typically achieved by ensuring causally related writes are replicated and applied together, or in a way that preserves their original order, rather than independently and in a potentially different order.
Consistent prefix reads
Consistent prefix reads guarantees that causally related writes are seen in their original order by any reader, never showing a later, dependent write before the earlier write it depended on.
Example: hearing the second half of a phone conversation before the first half, due to a delay scrambling arrival order, is exactly the glitch consistent prefix reads prevents.
Remember this
Read-your-writes protects a user from their own write; monotonic reads protects against data appearing to move backward across a user's own successive reads; consistent prefix reads protects causally related writes from appearing out of order to any reader. All three are direct, concrete symptoms of the same underlying replication lag.
Quick notes
- Replication lag is the delay before a follower reflects a change already committed on the leader.
- Read-your-writes guarantees a user sees their own just-made write on their next read.
- Monotonic reads guarantees a user never sees an older value after already seeing a newer one.
- Consistent prefix reads guarantees causally related writes are seen in their original order.
- All three guarantees exist specifically to hide replication lag's effects from users, without eliminating the lag itself.