What Are Consistent Prefix Reads?

First of all the problem case…

Replication lag… imagine two people talking between each other. πŸ—£πŸ—£

  • Person A πŸ—£ : “How far can you see into the future Person B?”
  • Person B πŸ—£ : “About 10 seconds”

πŸ€” There can be times where this may appear in a different different order from an observer’s point of view, or too fast to make much sense…

Consistent Prefix Reads to the rescue?

This guarantee of Consistent Prefix Reads can resolve this problem case.

  • If a sequence of writes happen in a certain order, anyone reading those writes can see them appear in the same order…
  • πŸ‘€ Look out for this problem in partitioned (sharded) databases
  • If database always applies writes in a certain order, reads can always see a consistent prefix… so this particular anomaly cannot happen

How about distributed databases with different partitions?

In this situation there is no global ordering of writes…

  • πŸ‘Ž When a user reads from a database they may see older part of a database and some in a newer state
    • πŸ‘‰ One solution is to make sure any writes that are causality related to each other are written to the same partition
  • πŸ‘Ž Although in some applications, this cannot be done efficiently
    • πŸ‘‰ There are also algorithms that explicitly keep track of causal dependencies

2 thoughts on “What Are Consistent Prefix Reads?

Leave a comment