Consistency Model
Hello! After having explored the concept of isolation level yesterday, let’s now discuss consistency models.
A consistency model defines what expectations clients can have about the data they see, especially when there are multiple copies of the data and concurrent operations on it:
Multiple copies: A database composed of multiple nodes (replicas).
Concurrent access: Multiple clients performing operations (like reading or writing) on the same data at the same time.
The term expectations in this definition refers to the guarantees regarding the order and visibility of operations on data:
Order: Ensures that the operations occur in the same sequence for all users.
Visibility: Controls how quickly changes made by one become visible to others.
Consider a collaborative document editing system such as Google Docs with two users, Alice and Bob, editing the same document:
Alice adds a new paragraph.
Shortly after, Bob changes a different paragraph.
Now, a question arises: How will these changes appear to both Alice and Bob, as well as other users?
Order of operations: Refers to whether users will see these changes occur in the same sequence. For example, does everyone first see Alice's update, followed by Bob's, or can it vary depending on who is viewing it?
Visibility of operations: Refers to when these changes become visible to all users. Will Bob immediately see Alice’s paragraph addition, or could there be a delay? Similarly, when will Alice see Bob’s changes?
Same as yesterday with the concept of isolation levels, consistency models cover a range of guarantees:
A strong consistency model guarantees that all users see updates in the same order, and changes are immediately visible across (again, despite the existence of multiple replicas). This is referred to as linearizability.
On the other hand, a weak consistency model might cause some delay when changes become visible or even allow users to observe operations in different orders temporarily. For example, eventual consistency.
It’s important to note that stronger consistency comes with trade-offs. Systems that aim for strong consistency often have higher overhead, as they must ensure all copies of the data are updated instantly, which can slow down performance. On the other side, systems with weaker consistency can perform faster by tolerating delays in synchronization across the replicas.
Tomorrow, let’s explore the concept of consensus.