CONSISTENCY MODEL
Consistency models in distributed systems ensure that all nodes in a system have a uniform view of data. These models are critical for maintaining data integrity and performance. Two primary types of consistency models are data-centric consistency and client-centric consistency.
Data-Centric Consistency
Data-centric consistency models focus on the state of data across all nodes in a distributed system. They aim to ensure that all users or processes see a consistent view of the data. Data-Centric consistency models include:
- Strict Consistency: In a strict consistent system, every read operation on data returns the most recent write operation. This means that all replicas of the data are immediately consistent after each update.
Characteristics:
- Ensures that all nodes in the system agree on the order of operations.
- Guarantees that a read operation will reflect the most recent write operation, even if the read is performed on a different node than the write.
- Achieved through synchronous replication or coordination mechanisms like distributed transactions.
Examples:
- Traditional databases using ACID transactions (Atomicity, Consistency, Isolation, Durability) typically provide strong consistency.
- Sequential Consistency: Sequential consistency is a model in which the results of execution are as if all operations were executed in some sequential order, and each operation of a single process appears in this sequence in the order issued by that process. It ensures that the operations are consistent across all processes in the same order.
- Causal Consistency: Causal consistency ensures that if one operation causally depends on another, then all replicas of the data will see those operations in the same causal order.
Characteristics:
- Preserves causal relationships between related operations, ensuring that operations that are causally related are observed in a consistent order across replicas.
- Provides more flexibility than stict consistency while still maintaining ordering guarantees for dependent operations.
Examples:
- Some distributed databases and middleware systems support causal consistency to maintain logical dependencies between operations.
- Eventual Consistency: Eventual consistency guarantees that if no new updates are made to a given data item, eventually all replicas of that data item will converge to the same value. There is no strict time bound on how quickly this convergence happens.
Characteristics:
- Allows for replicas to diverge temporarily but ensures they eventually converge.
- Provides high availability as updates can be applied independently to different replicas.
- Requires conflict resolution mechanisms to reconcile conflicting updates.
Examples:
- NoSQL databases like Amazon DynamoDB or Cassandra often provide eventual consistency as a default, allowing for high availability and partition tolerance.
Client-Centric Consistency
Client-centric consistency models ensure consistency from the perspective of individual clients, focusing on the experience of each client rather than the system as a whole. These models are particularly useful in systems where clients may access the system from different locations. Some client-centric consistency models include:
- Monotonic Consistency:Monotonic consistency guarantees that if a process reads the value of a data item, it will not later read an older value of that same data item. This ensures that data only moves forward in time.
Characterstics
- Prevents rollback of observed values, maintaining a consistent progression of data states.
- Useful in scenarios where older data should not reappear after newer updates have been observed.
Examples:
- Some distributed systems and replicated databases support monotonic consistency to prevent inconsistencies caused by reordering of operations.
- Read-your-Writes Consistency:
Read-your-writes consistency guarantees that after a client writes a value to a data item, it will subsequently read the same value from any replica.
Characteristics:
- Ensures that a client's own updates are immediately visible to subsequent read operations.
- Provides a stronger guarantee than eventual consistency for operations performed by the same client or session.
Examples:
- Many web applications and cloud storage services provide read-your-writes consistency to ensure users see their own updates immediately.
- 3. Writes Follow Reads: Ensures that writes issued by a client are seen by the system in the order they follow reads. This model is useful when a client needs to update a value based on a previous read.