How to Achieve Linear Consistency in Single-Leader Replication: Challenges and Solutions
This article examines eventual and linear consistency in leader‑based replication, explains read‑your‑writes and shared‑data scenarios, discusses replication lag, failover trade‑offs, multi‑data‑center risks, and shows how consensus systems like ZooKeeper and etcd implement true linear consistency.
Final Consistency Guarantees
All replication models (leader‑based, multi‑leader, leaderless) suffer from replication lag, which can cause consistency anomalies, but most databases can provide eventual consistency, meaning replicas converge to the same value over an unspecified period.
We expect all replicas to eventually converge to the same value.
Eventual consistency tolerates a window where reads may return stale or no data; after time T the system should return the same value across all replicas.
Rethinking Linear Consistency
Linear consistency (single‑object operation consistency) requires that a read returns the value written by the same client (read‑your‑writes) or that there appears to be only one replica for shared data.
Single‑object operation consistency: for exclusive data we expect read‑your‑writes; for shared data we expect a single logical replica.
Implementing linear consistency on a single‑leader replication architecture faces two main challenges: replication lag for reads and the need for atomic compare‑and‑set (CAS) for concurrent writes.
Read‑Your‑Writes Scenario
If a client writes to the leader and reads from the leader, the latest value is seen; reading from a follower may return no data due to lag. Applications such as posting a status, registering a user, or changing a password require read‑your‑writes guarantees.
Shared Data Scenario
For shared resources (e.g., meeting‑room booking), all clients must see a consistent state after a successful write. This requires a time‑based ordering guarantee and atomic write semantics, often implemented with CAS and versioned snapshots.
Linear Consistency in Single‑Leader Replication
Two approaches are common:
Read only from the leader, treating followers as backup‑only nodes. This reduces availability but eliminates stale reads.
Allow one follower to serve reads after synchronous replication from the leader, trading off write latency for higher read availability.
Failover to a follower introduces a period of unavailability while the new leader catches up, increasing RTO.
Multi‑Data‑Center Considerations
Network latency and failures increase the risk of split‑brain scenarios, where two data centers elect different leaders, leading to divergent data and potential security issues.
Practical Implementations
Consensus‑based services such as ZooKeeper, etcd, and systems using Raft, Paxos, or ZAB achieve linear consistency by sacrificing performance and availability.
Quorum‑based approaches may approximate linear consistency but cannot guarantee it in all cases.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Xiaokun's Architecture Exploration Notes
10 years of backend architecture design | AI engineering infrastructure, storage architecture design, and performance optimization | Former senior developer at NetEase, Douyu, Inke, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
