NOTE
4.5 Distributed-System Replication Methods
Replication modes determine how many replica acknowledgments the leader waits for and when clients receive success. These notes compare synchronous and asynchronous replication.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Synchronous Replication
A write succeeds only after the Leader has replicated it to all Followers.
- The client sends a request to the Leader.
- The Leader writes the data locally.
- The Leader replicates the data to Followers.
- The Leader returns success to the client.
2. Asynchronous Replication
A write succeeds once the Leader has written it locally.
- The client sends a request to the Leader.
- The Leader writes the data locally.
- The Leader returns success to the client.
- The Leader replicates the data 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
A write succeeds only after the Leader has replicated it to at least one Follower.
- The client sends a request to the Leader.
- The Leader writes the data locally.
- The Leader replicates the data to follower1.
- The Leader returns success to the client.
- The Leader replicates the data 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 to clients | High. The primary does not need to wait for replicas to finish replication before responding to clients | 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.
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub