# Replication lag

Symptom: the Replication Lag metric climbs; secondary reads return stale data; failover would lose recent writes.

## Diagnose

1. Atlas Metrics: replication lag per node, plus CPU and disk on the lagging secondary. A saturated secondary cannot apply the oplog fast enough.
2. Look for long-running writes on the primary: huge multi-updates and index builds generate oplog volume that buries secondaries.
3. Check the oplog window: if the window is short, a lagging secondary risks falling off entirely.

## Confirm

If lag correlates with primary write spikes or an index build, it is load-induced. If one secondary lags while others keep up, that node is undersized or unhealthy.

## Fix

- Move heavy batch work off peak; split huge multi-updates into smaller batches.
- Build big indexes with the rolling build option on dedicated clusters so secondaries are not buried.
- If a secondary is persistently behind on normal load, the tier is undersized: scale up.

## Verify

Lag returns to near zero and stays there through a normal write peak. Reads with secondary read preference return fresh data.