SQL.What is eventual consistency ?

Eventual consistency means that if no new updates are made, all replicas will eventually converge to the same state, but reads may temporarily see stale data.

Key phrase to remember:

Consistency is delayed, not lost.


Why eventual consistency exists

Strong consistency across nodes requires:

  • distributed locks
  • synchronous replication
  • blocking on network failures

That kills:

  • latency
  • availability
  • scalability

Eventual consistency trades immediate correctness for:

  • high availability
  • low latency
  • fault tolerance

Concrete example (classic)

Bank balance replicated to two regions

Client → Region A → balance = 100 → 90 (withdraw)
                 ↘
                  Region B still sees balance = 100

For a short time:

  • Region A: 90
  • Region B: 100

Later:

  • replication catches up
  • both show 90

That window = eventual consistency gap

Where eventual consistency is used

  • Distributed databases (Cassandra, DynamoDB)
  • Caches (Redis replicas)
  • Search indexes
  • OLAP replicas
  • Microservices with async messaging
  • CDC-based pipelines

Eventual vs Strong consistency

AspectStrong ConsistencyEventual Consistency
Read after writeAlways latestMight be stale
AvailabilityLowerHigher
LatencyHigherLower
Partition toleranceLimitedHigh
ComplexityLower for appHigher for app

Eventual consistency & CAP theorem

CAP says:

  • Consistency
  • Availability
  • Partition tolerance

In distributed systems:

You must choose between C and A when a partition happens.

Eventual consistency is typically:

  • AP system

What “eventual” really implies (important!)

It does NOT mean:

  • random
  • inconsistent forever
  • unreliable

It DOES mean:

  • ordering may differ temporarily
  • duplicates may appear
  • reads may lag behind writes

Backend implications (very important)

1️⃣ You must design for it

Assume:

  • duplicate events
  • out-of-order messages
  • delayed visibility

Therefore:

  • idempotent writes
  • versioning / timestamps
  • retry-safe operations

2️⃣ User-facing semantics matter

Examples:

  • “Your balance may update in a few seconds”
  • “Report data is delayed by up to 5 minutes”

Clear contracts > false guarantees.


3️⃣ Common consistency patterns

  • Read-your-writes (session consistency)
  • Monotonic reads
  • Causal consistency
  • Compensating actions

Eventual consistency has levels, not just one mode.


Eventual consistency in Kafka / CDC pipelines

Your earlier architecture:

  • Kafka → OLTP → CDC → OLAP

This is eventually consistent:

  • Transaction visible in OLTP immediately
  • Appears in OLAP after some delay

That’s fine for:

  • reports
  • dashboards
  • analytics

But NOT fine for:

  • real-time balance checks
  • authorization decisions

Interview-ready short answer

“Eventual consistency means that replicas may temporarily diverge, but if no new updates occur, they will converge to the same state. It’s a trade-off that improves availability and scalability at the cost of immediate consistency, and it requires applications to handle stale reads and retries.”

This entry was posted in Без рубрики. Bookmark the permalink.