Datareplica lag

Replication lag

Definition

Replication lag is the time, or the amount of log, by which an asynchronous replica trails the primary.

In practice

Lag is usually milliseconds but grows under heavy writes, long-running queries on the replica or network trouble. During lag, users can fail to see their own writes, see data go backwards between requests, or read stale balances.

Common mitigations are read-your-writes (route a user to the primary for a short time after they write), monotonic reads (pin a user to one replica) and alerting on lag. Lag also bounds data loss: anything not yet replicated is lost if the primary dies.

Example

A user updates their profile, the page reloads from a replica 2 seconds behind and shows the old name, which looks like the save failed.