Replication maintains multiple copies of data in different locations and keeps them synchronized. A nearby copy can reduce access latency; copies on different nodes can also improve availability when a node or network path fails. A content delivery network uses geographically distributed copies to serve users without requiring every request to reach a distant location. section 4.0 section 4.1
Keeping copies in sync is the central cost. Stricter consistency generally requires more coordination and increases latency. Replication extends colocation to multiple locations, overlaps with caching, and can be combined with partitioning to copy only selected portions of a dataset. section 4.1 section 5.3.5
The timing of a write acknowledgment changes what clients can observe:
- With asynchronous replication, the primary acknowledges a write before replicas have applied it. This reduces write latency but leaves a period when copies differ; a primary failure can also cause data loss. section 4.5
- With synchronous replication, the primary waits for replication to complete before acknowledging the client. The wait adds coordination to the write path. section 4.5
- A client that writes and then reads from a lagging replica may not see its own update. Check whether a replicated system guarantees read-your-writes rather than assuming that it does. section 4.4.4
A small primary–replica key–value store
Start with an in-memory hash map on the primary and replica. Direct writes to the primary, which broadcasts each Put update; let the replica serve local reads. A new replica sends Join and receives a Snapshot of existing entries before receiving incremental updates. In the example shell, keys a and b are absent on the replica before JOIN, appear after the snapshot, and a later write of c becomes readable there after its update. section 4.8
pub enum Message {
Put { key: String, value: String },
Join { replica_addr: String },
Snapshot { entries: Vec<(String, String)> },
}
The message types show the protocol’s three operations: push an update, register a replica, and initialize it with existing data. section 4.8
Copying popular partitions to multiple nodes can increase read concurrency, but it also consumes more resources and requires a replication protocol to keep those copies consistent. Choose the copies and acknowledgment timing for the latency, availability, and consistency guarantees the application needs. section 5.3.5 section 4.0












