liveBook · Manning

Replication lag

As explained in Fast by Default

Replication lag is the delay between a change being committed on a source database and becoming available on a replica.

Replication lag is the delay between a change being committed on a primary database and becoming visible on a replica. Read replicas increase capacity for read-heavy workloads, but replicas can fall behind by milliseconds or seconds under load. section 5.4.2

Replication strategy creates a direct trade-off:

  • Synchronous replication waits for replica confirmation, minimizing lag while adding latency to every write. section 5.4.2
  • Asynchronous replication lets the primary continue immediately, improving write performance while allowing replicas to fall behind. section 5.4.2
  • Treat read-your-writes operations carefully: a user may update data on the primary and then receive stale data from a replica. section 5.4.2 section 5.4.4

A profile update that appears to vanish

A user updates their profile, then immediately views it. If the follow-up read goes to a replica that has not received the update, the change appears to disappear. Route such reads appropriately or accept eventual consistency only where the delay is acceptable. section 5.4.2

Measure lag under normal conditions and peak load, then relate it to user expectations. Audit read routing, connection counts, pool utilization, and database statistics before deciding whether replicas, write scaling, or another database pattern addresses the bottleneck. section 5.4.4

How Fast by Default covers it

How deep it goes
Defines lag, contrasts synchronous and asynchronous replication, and emphasizes measurement without detailing a complete mitigation implementation.
Examples
Uses a profile-update read routed to a stale replica and PostgreSQL deployments scaled with many read replicas.
What it assumes
Assumes primary databases, replicas, and read/write routing, while defining the delay and its user-facing consequences.
What you can do after
Diagnose replication lag under normal and peak load, then adjust read routing for operations requiring read-your-writes consistency.
How it connects
Connects read replicas with synchronous replication, asynchronous replication, eventual consistency, read-your-writes consistency, connection pooling, and sharding.

Also explained in

Compare how 6 books explain replication lag →

Related concepts

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