Open In App

Sequential Consistency In Distributive Systems

Last Updated : 17 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

What is the problem if we do not maintain consistency in Distributive systems?

What is Consistency?

Consistency is a fundamental property of distributed systems that ensures that all replicas of a shared data store have the same value. In a distributed system, data is typically replicated across multiple nodes to improve availability and fault tolerance. However, maintaining consistency across all replicas can be challenging, especially in the presence of concurrent updates and network delays.

Inconsistency problem in distributed systems

When multiple processes access shared resources concurrently, where the order of execution is not deterministic, the problem arises due to the need for maintaining consistency across these processes.

This challenge is further complicated by the fact that distributed systems are prone to various types of failures, such as message losses, network delays, and crashes, which can lead to inconsistencies in the execution order.

So, how to solve this inconsistency problem in distributed systems?

To ensure that shared resources are accessed in a consistent order by consistency, there are several consistency models that can be used in distributed systems. These models define the level of consistency that is guaranteed for shared resources in the presence of concurrent access by multiple processes.

What is the Consistency Model?

A consistency model is a set of rules or guidelines that determine how a distributed system should behave in terms of the ordering and visibility of updates made to shared data.

In a distributed system, where multiple nodes can access and modify the same data, it’s important to ensure that all nodes have a consistent view of the data to avoid conflicts and inconsistencies. A consistency model defines the level of consistency required for the system and specifies the mechanisms used to achieve it.

Different consistency models offer different trade-offs between consistency and performance, and they may prioritize factors such as availability, partition tolerance, or the level of coordination required between nodes.

Following are the different kinds of consistency models:

Eventual Consistency

  • Weakest form of consistency.
  • This ensures high availability and returns the same value for READ requests.
  • One popular example is Cassandra – ( NoSQL, highly available ).

Causal Consistency

  • Has consistency stronger than eventual consistency.
  • Preserves the order of casually-related(dependent) operations.
  • So, that’s why it does not ensure the ordering of operations that are non-causal.
  • One example is Comment replies.

Sequential Consistency

  • Stronger than causal consistency.
  • Doesn’t ensure writes are visible instantaneously or in the same order as according to some global block.
  • One example is that of facebook posts of friends (sequential for a particular friend, but not for overall)

Strict Consistency/ Linearizability

  • This is the strongest consistency model.
  • All read requests are consistent as they get the latest write value
  • One popular example is password update of someone’s bank account.

Why to use sequential consistency as a consistency model in distributive systems?

Every concurrent execution of a program should ensure that the results of the execution are to be in some sequential order. It provides an intuitive model of how the distributed systems should behave, which makes it easier for users to understand and reason about the behavior of the system.

Sequential Consistency:

Sequential consistency is a consistency model that ensures that the order in which operations are executed by different processes in the system appears to be consistent with a global order of execution. It ensures that the result of any execution of a distributive system is the same as if the operations of all the processes in the system were executed in some sequential order, one after the other.

Example of Sequential Consistency

Sequential Consistency Example

Let us consider a distributive system here for four different processes, P1, P2, P3, and P4. Here, several different operations are occurring simultaneously, such as W(X, A) updating the value of X to be A, and R(X) reading the value of X.

Now, if we follow the given global order of operations, we get a sequentially consistent system.

W(X,A), R(X) = A, W(Y,B), R(Y) = B

With this sequential order, it makes sense that P3 reads A first and then B in subsequent read operations.

Techniques to implement Sequential Consistency

The following techniques can be used to implement sequential consistency in distributed systems:

  • Two-Phase Locking: Two-phase locking is a technique used to ensure that concurrent access to shared data is prevented. In this technique, locks are used to control access to shared data. Each process acquires a lock before accessing the shared data. Once a process acquires a lock, it holds the lock until it has completed its operation. Two-phase locking ensures that no two processes can access the same data at the same time, which can prevent inconsistencies in the data.
  • Timestamp Ordering: Timestamp ordering is a technique used to ensure that operations are performed in the same order across all nodes. In this technique, each operation is assigned a unique timestamp. The system ensures that all operations are performed in the order of their timestamps. Timestamp ordering ensures that the order of operations is preserved across all nodes.
  • Quorum-based Replication: Quorum-based replication is a technique used to ensure that data is replicated across different nodes. In this technique, the system ensures that each write operation is performed on a subset of nodes. To ensure consistency, the system requires that a majority of nodes agree on the value of the data. Quorum-based replication ensures that the data is replicated across different nodes, and inconsistencies in the data are prevented.
  • Vector Clocks: Vector clocks are a technique used to ensure that operations are performed in the same order across all nodes. In this technique, each node maintains a vector clock that contains the timestamp of each operation performed by the node. The system ensures that all operations are performed in the order of their vector clocks. Vector clocks ensure that the order of operations is preserved across all nodes.

Some common challenges in achieving Sequential Consistency

  • Network Latency: Communication between different nodes in a distributed system can take time, and this latency can result in inconsistencies in the data.
  • Node Failure: In a distributed system, nodes can fail, which can result in data inconsistencies.
  • Concurrent Access: Concurrent access to shared data can lead to inconsistencies in the data.
  • Replication: Replication of data across different nodes can lead to inconsistencies in the data.

Achievement after implementing Sequential Consistency

After implementing sequential consistency in a distributed system, the system then provides a high level of consistency guarantee for shared resources. This means that the system ensures that the order of operations on a shared resource is consistent with the order in which they were issued by processes. As a result, the final state of the resource is the same as if the operations had been executed serially, even though they may have been executed concurrently by multiple processes.

Thus, this ensures that the system behaves correctly and consistently which is really essential and critical for several applications in fields of financial systems and mission-critical systems, also in databases of big applications. Thus, it ensures high reliability and consistency of the system.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads