Part 09 · Distributed Systems

Consistency, replication và availability

Consistency là contract quan sát theo scope; eventual consistency cần trạng thái và UX trung thực.

CAP đúng scope

Khi network partition xảy ra giữa replicas, hệ thống phải chọn cho operation cụ thể giữa availability và consistency. CAP không nói bình thường chỉ được hai trong ba, cũng không thay latency/durability analysis.

Replication

Leader-based đơn giản ordering nhưng failover có lag; multi-leader tăng write availability nhưng cần conflict resolution; leaderless dùng quorums/repair với nhiều nuance. Replication factor không tự bảo đảm read freshness hay backup.

Session guarantees

Read-your-writes có thể dùng primary read, sticky/session token, version-aware wait hoặc update local view. Monotonic reads tránh thấy state quay lùi. Expose PENDING/PROCESSING/FAILED thay vì trả COMPLETED trước khi workflow hoàn tất.

Reconciliation

Periodic job so source-of-truth với downstream/materialized views, phát hiện missing/duplicate/stuck state và repair idempotently. Reconciliation là thành phần reliability bình thường.

Compensating Transaction · PostgreSQL Replication Concepts