replication lag

term

cloudops culture

Kept 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

← Back to R Back to the glossary