liveBook · Manning

Replication

As explained in Latency

A replication protocol is a protocol that coordinates the creation, updating, and consistency of multiple copies of data or state.

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

How Latency covers it

How deep it goes
Explains acknowledgment timing and replication lag, then works through a simple primary–replica protocol rather than a production-grade implementation.
Examples
Uses a CDN and an in-memory key–value store with Join, Snapshot, and Put messages.
What it assumes
Assumes client–server and key–value concepts, but does not require Rust to apply the latency technique.
What you can do after
Build it from scratch as a simple Rust primary–replica key–value store with snapshot-based joins and broadcast updates.
How it connects
Connects replication to colocation, caching, partitioning, consistency models, and read-your-writes.

Also explained in

Compare how 13 books explain replication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.