Distributed Data Consistency Patterns

Ý chính

Khi dữ liệu nằm trên nhiều service, database hoặc region, consistency không còn là một tính chất mặc định. Nó là một lựa chọn theo từng invariant: dữ liệu nào cần đúng ngay, dữ liệu nào được stale, workflow nào cần compensation, và coordination nào đáng trả latency.

Map quyết định

Nhu cầuPatternGiá phải trả
Mọi read sau write phải thấy giá trị mớiStrong ConsistencyConsensus, quorum latency, giảm availability khi mất majority
Dữ liệu được phép stale trong một cửa sổEventual ConsistencyConflict resolution, observability cho lag và hội tụ
Workflow nhiều service không dùng transaction toàn cụcSaga PatternCompensating action và debugging event flow
Đồng bộ read store/index/warehouseChange Data CaptureCoupling với log, consumer lag, replay
Publish event cùng transaction với state changeTransactional OutboxThêm outbox table và publisher lifecycle
Cần một node điều phối write/logLeader ElectionElection timeout, quorum, split-brain safety

Mental model

business invariant
-> chọn consistency guarantee
-> chọn coordination hoặc async sync
-> thiết kế failure/compensation
-> đo lag, conflict, retry và user-visible stale read

Ghi nhớ

Strong consistency không miễn phí, nhưng eventual consistency cũng không miễn phí. Một bên trả bằng coordination/latency; bên kia trả bằng application logic, compensation, read-your-writes handling và observability.

Liên kết