Course contentsShow
← Databases & SQL
Lesson 1221 of 1,95311. NoSQL and Document ModelsFree lesson

Causal Consistency Models

Explain the trade-offs between linearizability and performance in distributed document systems.

In this lesson, you will learn how causal consistency balances the strict requirements of linearizability with the performance needs of a distributed document system.

The Conflict: Speed vs. Truth

In a distributed document store, Linearizability represents the "gold standard" of consistency: every read is guaranteed to return the absolute latest write. To achieve this, your database must coordinate across nodes, often forcing the system to wait for confirmation from a majority of replicas. In a global system, this "chatter" between nodes introduces significant latency, hurting your application's performance.

Causal Consistency offers a middle ground. It recognizes that not every operation needs to be perfectly ordered globally; it only matters that causally related operations appear in the correct sequence.

What is Causal Consistency?

Two operations are causally related if one could have influenced the other. For example, if you post a comment and then another user replies to that comment, the reply is causally dependent on the original post.

Under causal consistency, the system guarantees that:

  1. If Operation A causes Operation B, all nodes see A before B.
  2. Concurrent operations (unrelated events) may be seen in different orders by different users.

This is much faster than linearizability because the database doesn't need to force a global "clock" or stop all traffic to ensure perfect consensus. Instead, it tracks dependencies locally.

Performance in Practice

Imagine you are building a document-based forum. If you use a linearizable model, every time a user refreshes their feed, the system must perform a synchronous global sync to ensure they see the absolute latest post.

If you use a causal model, the system ensures that if a user sees a thread, they are guaranteed to see the original post before they see any replies to it. However, the system won't waste time synchronizing that thread with a totally unrelated thread happening on a different shard. You get a "logical" order that feels consistent to the human eye, without the massive performance tax of global locking.

Key Takeaway: Causal consistency provides a high-performance alternative to linearizability by only enforcing the order of related operations, ensuring that cause-and-effect relationships remain intact without requiring global synchronization.