liveBook · Manning

Replication lag

As explained in MongoDB 8.0 in Action, Third Edition

Replication lag is the delay between an operation being recorded or applied on the primary and being applied on a replica.

Replication lag measures the delay between an operation being recorded or applied on the primary and being applied on a replica. It helps reveal whether replicas are keeping pace and supports operational diagnosis. section 9.1.3

Use replication lag when evaluating replication behavior:

  • Chained replication can reduce primary load, but routing a secondary through another secondary may increase lag depending on network topology. section 9.1.3
  • Compare each secondary’s synced timestamp with the primary to identify members that are behind. section 9.1.3

Inspect secondary lag

Run db.printSecondaryReplicationInfo(). Its output reports each secondary’s source, syncedTo timestamp, and replLag value; one member may show 0 seconds behind while another shows 10 seconds.

Listing 9.5 Output of the db.getReplicationInfo() command
db.getReplicationInfo()
{
  configuredLogSizeMB: 4096,
  logSizeMB: 4096,
  usedMB: 4074.63,
  timeDiff: 635133,
  timeDiffHours: 176.43,
  tFirst: 'Wed Mar 20 2024 10:44:15 GMT+0000 (Coordinated Universal Time)',
  tLast: 'Wed Mar 27 2024 19:09:48 GMT+0000 (Coordinated Universal Time)',
  now: 'Wed Mar 27 2024 19:09:49 GMT+0000 (Coordinated Universal Time)'
}

Inspect db.getReplicationInfo() output to review oplog size, usage, time span, and timestamps when diagnosing replication problems. section 9.1.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains topology-related causes and demonstrates status commands, but does not develop a formal lag calculation.
Examples
Uses db.getReplicationInfo() and db.printSecondaryReplicationInfo() outputs showing oplog timing and per-secondary lag.
What you can do after
Diagnose replication status with MongoDB shell commands and identify secondaries that trail the primary.
How it connects
Connects replication lag with oplog, chained replication, replica sets, secondary members, and network topology.

Also explained in

Compare how 2 books explain replication lag →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.