Consistency

Every read receives the most recent write or an error

“Consistency means that all nodes see the same data at the same time.” – Eric Brewer

In CAP, this specifically refers to Linearizability (Atomic Consistency).

When to use

When data accuracy is critical (Financial transactions, Inventory management).

Why it matters

  • Truth: Users don’t see outdated data. If I transfer $100, my balance updates immediately everywhere.

Signs of Violation

  • User A posts a comment. User B refreshes page but doesn’t see it for 5 seconds.
  • Selling the same plane ticket to two people because the DBs weren’t synced.

Explanation

Problem

In a distributed system with multiple nodes, keeping them all perfectly synced in real-time is hard if the network is slow or broken.

Solution

To guarantee Consistency, you must lock all nodes during a write until they all agree. This hurts Availability (if one node is down, the write fails).

Real world analogy

A classroom roll call. The teacher checks off “Alice”. If another teacher asks “Is Alice here?”, they must check the official list. If the list is being updated, they wait. They don’t guess.

Pros and Cons

Pros Cons
  • Data Integrity
  • Simplicity for app logic
  • High Latency (waiting for sync)
  • Lower Availability (CAP theorem)
  • Comparison

    • Eventual Consistency: The opposite. “You’ll see the data eventually”.
    • ACID Consistency: slightly different (refers to database rules), but related.

    Code example

    Typescript

    Bad (Violation - Eventual)

    Good (Adherence - CP System)

    PHP

    Bad (Violation)

    Good (Adherence)