replication lag
termKept in this browser · My desk
How far a replica trails the copy it follows, in time or in writes; for asynchronous replication it is the data a failover would lose.
PostgreSQL's documentation states that with asynchronous streaming replication the data lost in a failover is proportional to the replication delay at that moment, and exposes the delay as write, flush and replay lag in pg_stat_replication. Kafka removes a follower that falls too far behind from its in-sync replicas, so it can no longer become leader. Lag also turns into wrong answers: after GitHub's October 2018 failover, read replicas hours behind showed users inconsistent data, and catch-up followed a power decay rather than a straight line, so every estimate was too short.
Measuring it. In PostgreSQL 18, write_lag, flush_lag and replay_lag are the time between flushing WAL locally and hearing that the standby has written, flushed or applied it, and they show what each synchronous commit level would have cost. Kafka 4.2 exposes under-replicated and under-minimum-ISR partition counts. Converting it into loss. At an illustrative 500 writes a second, two seconds of lag is up to 1,000 writes; GitHub's report gives the real figure of 954 unreplicated writes on one busy cluster when a 43-second partition triggered a cross-country failover. When it breaks replication. GitLab's 2017 secondary fell so far behind under load that the write-ahead log segments it needed had already been removed from the primary, which forced the manual rebuild during which the primary was wiped by mistake. Bounding it. Synchronous replication removes the lag for the copies it waits for, at the price of at least one round trip per commit and of stalled writes if its only synchronous standby fails.
Also known as: replica lag, replay lag, replication delay, atraso de replicação
Sources
- PostgreSQL 18 documentation, 26.2.8 Synchronous Replication (read 2026-11-16): streaming replication is asynchronous by default and the data lost in a failover is proportional to the replication delay at that moment
- PostgreSQL 18 documentation, 27.2 The Cumulative Statistics System, pg_stat_replication (read 2026-11-16): write_lag, flush_lag and replay_lag measure the time for recent WAL to be written, flushed and replayed on the standby
- Apache Kafka 4.2 documentation, Design, Replication (read 2026-11-16): a follower that cannot catch up within the configured time is removed from the in-sync replicas, and only in-sync replicas are eligible as leader
- GitHub, October 21 post-incident analysis, 30 October 2018 (read 2026-11-16): 954 writes on one busy cluster had not replicated when a cross-country failover happened; read replicas hours behind showed users inconsistent data; catch-up followed a power decay, not a line
- GitLab, Postmortem of database outage of January 31, 10 February 2017 (read 2026-11-16): under load the secondary fell so far behind that the WAL segments it needed had been removed from the primary