/kənˈsɪstənsi/
noun … “All nodes see the same data at the same time.”
Consistency is the property of a Distributed System that ensures every read operation returns the most recent write for a given piece of data. In the context of the CAP Theorem, consistency guarantees that all nodes observe the same state even in the presence of concurrent updates or network failures. Strong consistency simplifies reasoning about system behavior, as clients can assume a single, globally agreed-upon value for each piece of data.
Key characteristics of Consistency include:
- Linearizability: operations appear instantaneous and in some global order.
- Atomicity of updates: writes are applied fully or not at all across all replicas.
- Deterministic reads: the system ensures that the same query issued at the same logical time returns identical results from any node.
- Tradeoff with availability: during network partitions, maintaining consistency may require rejecting or delaying operations to prevent divergent states.
- Coordination mechanisms: consensus algorithms, locks, or quorum-based protocols are commonly used to enforce consistency across nodes.
Workflow example: In a replicated database with three nodes, a client writes a value to Node1. Before returning success, the system ensures that at least a majority of nodes have applied the update. Subsequent reads from any node return the same value, guaranteeing consistency even if one node is temporarily unreachable.
-- Example: simplified quorum write
nodes = ["Node1", "Node2", "Node3"]
value_to_write = 42
quorum_size = 2
successful_writes = 0
for node in nodes {
if write(node, value_to_write) > 0 { -- write returns 1 if successful
successful_writes += 1
}
if successful_writes >= quorum_size:
break
}
print("Write committed with quorum")
-- Output: Write committed with quorumConceptually, Consistency is like multiple clocks in a networked building synchronized to show the same time. Even if one clock temporarily stops or drifts, the system ensures that all visible clocks agree once synchronization completes.
See Distributed Systems, CAP Theorem, Partition Tolerance, Availability, Consensus.