Eventual consistency

System will become consistent over time if input stops

“If no new updates are made to a given data item, eventually all accesses to that item will return the last updated value.”

Part of the BASE acronym.

When to use

Social feeds, Search indexing, Analytics, DNS.

Why it matters

  • Performance: Writing to 1 node is faster than writing to 5.
  • Scale: Allows the system to ingest massive amounts of data without locking.

Signs of Violation

  • App crashes if the “Read” doesn’t immediately match the “Write”.

Explanation

Problem

Instant consistency requires locking, which is slow.

Solution

Let the data ripple through the system asynchronously. It might take milliseconds or seconds.

Real world analogy

Email. You send an email. It lands in the “Sent” box. It doesn’t appear in the recipient’s “Inbox” instantly. It travels through relays. Eventually, the state is consistent (both sides see the email).

Pros and Cons

Pros Cons
  • Low latency writes
  • High throughput
  • “Stale reads” can confuse users
  • Comparison

    • Strong Consistency: ACID.
    • Causal Consistency: A middle ground.

    Code example

    Typescript

    Good (Adherence)

    PHP

    Good (Adherence)