NOTE
4.5 Distributed-System Replication Methods
1. Synchronous Replication - The Leader succeeds only after synchronizing to all Followers. 1. The client requests the Leader. 2. The Leader writes local data. 3. The Leader synchronizes to Followers. 4. The Leader returns success to the client. 2. Asynchronous Replication - The Leader succeeds once it writes locally.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Synchronous Replication
The Leader succeeds only after synchronizing to all Followers.
- The client requests the Leader.
- The Leader writes local data.
- The Leader synchronizes to Followers.
- The Leader returns success to the client.
2. Asynchronous Replication
The Leader succeeds once it writes locally.
- The client requests the Leader.
- The Leader writes local data.
- The Leader returns success to the client.
- The Leader synchronizes to Followers.
2.1. Replication-Lag Problem
- Scenario
- In read-heavy, write-light scenarios, a read/write separation model is generally used: writes go only to the Leader, while reads go to Followers. In this scenario, adding Follower nodes can improve read throughput, and asynchronous replication is generally configured. However, asynchronous replication has a consistency problem. The period of inconsistency, when the Leader has not yet synchronized to a Follower, is called replication lag.
- Example problems
- Read after write.
- Monotonic read.
- Consistent-prefix read.
- Solution
- Solve it through distributed consistency models. Different consistency models solve replication lag to different degrees.
- Distributed Consistency Models
3. Semi-Synchronous Replication
The Leader succeeds only after synchronizing to at least one Follower.
- The client requests the Leader.
- The Leader writes local data.
- The Leader synchronizes to follower1.
- The Leader returns success to the client.
- The Leader synchronizes to follower2.
4. Synchronous vs Asynchronous vs Semi-Synchronous
| Synchronous | Asynchronous | Semi-synchronous | |
|---|---|---|---|
| Consistency | High. Replica data remains consistent with the primary | Low. Data present on the primary may not be present on replicas | Medium |
| Availability | Low. The primary must wait for replicas to finish replication before responding externally | High. The primary does not need to wait for replicas to finish replication before responding externally | Medium |
5. Examples
- MySQL supports synchronous, asynchronous, and semi-synchronous replication.
- Redis supports asynchronous replication.
- Kafka supports synchronous, asynchronous, and semi-synchronous replication.
- ZooKeeper supports synchronous replication.
- Elasticsearch supports synchronous replication.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub