Lesson 5 of 17
16. Consistency and CAP

16.4 What are read-your-writes and monotonic reads?

3 min read+10 XP

At the bank: Between "one ledger" and "couriers whenever", there are useful promises to one customer: "after you deposit, you'll always see it" and "once you've seen a balance, you'll never be shown an older one".

In the system: These are session guarantees, weaker than strong consistency but much cheaper, and they fix the bugs users actually notice (Chapter 14, section 14.5):

GuaranteePromiseTypical fix
Read-your-writesYou always see your own writesRead from the leader for a while after you write, or wait for the replica to reach your write's log position
Monotonic readsYou never see data go backwardsKeep each user on the same replica
Monotonic writesYour writes are applied in the order you made themSend a user's writes through one leader or sequence them
Causal consistencyIf B was caused by A (a reply to a comment), everyone who sees B also sees ATrack dependencies; deliver in order

Causal consistency deserves a mention: it's one of the strongest models that can still stay available during partitions, and it's exactly what comment threads and chats need: nobody should see a reply before the message it answers.

Memory code: "Show me my own deposit, never go back in time, and never show the answer before the question."