🎓 A1Learner
🔍
0 of 47 lessons completed

Consistency in Plain Words

Consistency is the property that every copy of the same data shows the same value at the same time. A system keeps copies so data survives a failed machine, and consistency keeps those copies in agreement.

Two copies that agree

Two replicas start with the same stored name. A read from each replica returns the same value.

replica_a = "Ada"
replica_b = "Ada"
print("Read from replica A:", replica_a)
print("Read from replica B:", replica_b)
print("Values agree:", replica_a == replica_b)

A write that reaches only one copy

A write changes the name in the first replica only. The two reads now return different values, and the stale value stays in the second replica.

replica_a = "Ada"
replica_b = "Ada"
replica_a = "Grace"
print("Read from replica A:", replica_a)
print("Read from replica B:", replica_b)
print("Values agree:", replica_a == replica_b)

A write that reaches both copies

The same write changes the name in both replicas. The two reads agree again.

replica_a = "Ada"
replica_b = "Ada"
replica_a = "Grace"
replica_b = "Grace"
print("Read from replica A:", replica_a)
print("Read from replica B:", replica_b)
print("Values agree:", replica_a == replica_b)

Example

replicas = ["Ada", "Ada"]
print("Start:", replicas)
replicas[0] = "Grace"
print("After one write:", replicas)
print("Values agree:", replicas[0] == replicas[1])
replicas[1] = "Grace"
print("After the write reaches both:", replicas)
print("Values agree:", replicas[0] == replicas[1])

Key points

  • Consistency: all copies of one piece of data hold the same value.
  • Replica: one copy of the same data stored on another machine.
  • Stale value: an older value that one copy still holds after a newer write.
  • Disagreement: two copies return different values for the same data.

In this example, the two replicas disagree after the write reaches only the first replica, and they agree again once the same write reaches the second replica.

Note

consistency is about copies agreeing, and it says nothing about how fast a read is.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

A write updates one replica but not the other. What has the system lost?