Skip to content

Eventual Consistency: Deep Dive & Real-World System Design Use Cases

1) Problem Clarification / Làm rõ khái niệm

EN

In distributed systems, perfect consistency is often impossible or prohibitively expensive.
Eventual consistency ensures state converges over time.

VI

Trong hệ thống phân tán, đảm bảo nhất quán tuyệt đối là khó hoặc quá đắt.
Eventual consistency đảm bảo trạng thái ổn định theo thời gian, không ngay lập tức.

2) Why Eventual Consistency Exists / Vì sao tồn tại eventual consistency?

EN

  • Network latency
  • Partition failures
  • Write replication lag
  • CAP theorem trade-offs

VI

  • độ trễ mạng
  • partition failure
  • chậm đồng bộ replicator
  • ràng buộc CAP

3) Where Eventual Consistency Applies / Ứng dụng ở đâu?

EN

✔ Social feeds
✔ Analytics/logging
✔ E-commerce cart
✔ Search indexing
✔ Async projections (CQRS)

VI

✔ social feed
✔ analytics/log
✔ giỏ hàng ecommerce
✔ search indexing
✔ async projection

4) Guarantees of Eventual Consistency / Các đảm bảo trong EC

EN

  • Writes propagate to replicas eventually
  • No guarantee when
  • Reads may be stale temporarily

VI

  • dữ liệu ghi sẽ lan tới replica
  • không cam kết thời gian cụ thể
  • đọc tạm thời có thể stale

5) Strong vs Eventual Consistency / So sánh Consistency mạnh vs EC

EN

Strong Consistency
→ read-after-write correctness guaranteed

Eventual Consistency
→ state becomes consistent over time

VI

Strong consistency
→ đọc luôn thấy đúng ngay sau ghi

Eventual consistency
→ thời gian sau mới đúng

6) Consistency Spectrum / Dải nhất quán

EN

Between strong and eventual:

  • read-your-own-write
  • monotonic reads
  • causal consistency
  • timeline consistency
  • session consistency

VI

Không chỉ 2 điểm:

  • read-your-own-write
  • monotonic
  • causal
  • timeline
  • session consistency

7) Designing for Eventual Consistency / Cách thiết kế hệ thống

EN

Key design principles:

  • asynchronous messaging
  • idempotent processing
  • retry-safe writes
  • compensating actions
  • versioning
  • conflict detection/merging (CRDTs)

VI

Thiết kế EC cần:

  • message async
  • logic idempotent
  • retry an toàn
  • transaction bù
  • version
  • detect/merge conflict (CRDT)

8) CQRS & Eventual Consistency / CQRS và EC

EN

Command writes → event sourcing → projections update asynchronously
Queries may read stale data.

VI

CQRS:

  • ghi / lệnh → event sourcing
  • projection update async
  • đọc có thể stale

9) Example #1 – Social Feed / Ví dụ Social feed

EN

When someone posts:

  • feed distribution asynchronous
  • followers see it shortly after

VI

Post mới:

  • phân phối async
  • follower thấy sau vài giây

10) Example #2 – Search Indexing

EN

Product created in DB
→ takes seconds/minutes to appear in search index

VI

Tạo sản phẩm DB → vài giây phút mới search được.

11) Example #3 – Shopping Cart

EN

Cart UI updates, backend validation later corrects mismatched state.

VI

UI update giỏ hàng nhưng backend có thể sửa sau khi verify.

12) Conflict Resolution / Xử lý xung đột

EN

Strategies:

  • last-write-wins
  • vector clocks
  • merge logic (union/CRDT)
  • user-driven resolution

VI

Cách giải quyết:

  • last-write-wins
  • vector clock
  • logic merge (CRDT)
  • hỏi user

13) Operational Patterns / Pattern vận hành

EN

  • retry loops
  • exponential backoff
  • DLQ
  • deduplication

VI

Pattern:

  • retry
  • backoff
  • DLQ
  • dedupe

14) When Not to Use Eventual Consistency? / Khi nào không dùng EC?

EN

  • Payment
  • Inventory control
  • Banking ledger
  • Ticketing / flash sale

VI

Không dùng EC cho:

  • thanh toán
  • tồn kho
  • banking ledger
  • ticket flash sale

15) Future of Consistency Models / Xu hướng tương lai

EN

  • CRDT adoption
  • vector clock improvements
  • edge computing consistency
  • Spanner global consistency models

VI

Xu hướng:

  • CRDT
  • cải tiến vector clock
  • consistency edge computing
  • global consistency kiểu Spanner
Published inAll

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *