Skip to main content

Data Consistency


Cloud applications typically use data that is dispersed across data stores. Managing and maintaining data consistency in this environment can become a critical aspect of the system, particularly in terms of the concurrency and availability issues that can arise. In a distributed environment, the inability to complete an operation is often due to some type of temporary error such as communication failure, or less transient exceptions, such as database or virtual machine failure, that may occur. If such a failure occurs, an application might assume that the situation is transient and simply attempt to repeat the step that failed. However, this approach could result in the same step being run twice, possibly resulting in multiple updates. It is difficult to design a solution to prevent this repetition from occurring, but the application should attempt to render such repetition harmless.

One common technique to mitigate the impact of duplication in distributed systems is to use de-duping, which removes duplicate messages. In this technique, the message sent to the service is associated with a unique identifier. The service can store the identifier for each message it receives locally and only process a message if the identifier does not match that of a message it received earlier. This technique ensures that the message is processed only once and reduces the risk of multiple updates.

In the world of relational databases, consistency is often enforced by transactional models that use locks to prevent concurrent application instances from modifying the same data at the same time. However, maintaining data consistency across distributed data stores can be a significant challenge. The issue is that strategies such as serialization and locking only work well if all application instances share the same data store, and the application is designed to ensure that the locks are very short-lived.

If data is partitioned or replicated across different data stores, locking and serializing data access to maintain consistency can become an expensive overhead that impacts the throughput, response time, and scalability of a system. Therefore, most modern distributed applications do not lock the data that they modify, and they take a rather more relaxed approach to consistency, known as eventual consistency.

Eventual consistency is a pragmatic approach to data consistency in distributed systems. In many cases, strong consistency is not actually required as long as all the work performed by a transaction is completed or rolled back at some point, and no updates are lost. In the eventual consistency model, data update operations that span multiple sites can ripple through the various data stores in their own time, without blocking concurrent application instances that access the same data.

The CAP Theorem drives the need for eventual consistency. This theorem states that a distributed system can implement only two of the three features (Consistency, Availability, and Partition Tolerance) at any one time. In practice, this means that you can either provide a consistent view of distributed (partitioned) data at the cost of blocking access to that data while any inconsistencies are resolved or provide immediate access to the data at the risk of it being inconsistent across sites.

In a cloud application, strong consistency should only be implemented where it is absolutely necessary. For example, if an application updates multiple items that are located within the same data store, the benefits of strong consistency may outweigh the disadvantages because data is likely to be locked only for a very short period. However, if the items to be updated are dispersed across a network, it may be more appropriate to relax the requirement for strong consistency.

In conclusion, managing and maintaining data consistency in a distributed environment is a critical aspect of a cloud application. While strong consistency is ideal, it can be expensive and impact the performance and scalability of the system. Eventual consistency is a more pragmatic approach to data consistency in distributed systems, where data update operations can ripple through various data stores in their own time, without blocking concurrent application instances that access the same data. In a cloud application, de-duping is a common technique used to mitigate the impact of duplication.