Replication lag is the delay between an update reaching a primary replica and being applied to another replica. It matters because asynchronous replicas may serve stale data while improving availability and read performance. section 6.5
Interview scenario: monitoring replica lag
A strong answer explains how to configure and observe lag rather than merely defining it. In PostgreSQL, inspect pg_stat_replication: sent_lsn records WAL sent, write_lsn records WAL written on the standby, and replay_lsn records WAL applied. Compare these positions with the primary's current WAL position. In MongoDB, use rs.status() and rs.printSlaveReplicationInfo() to inspect replication state and time differences. Then discuss write concern and read preference: requiring more replica acknowledgments can improve consistency, while primary, nearest, or secondaryPreferred reads trade consistency against latency. section 6.5
Connect the metric to operational decisions:
- Monitor lag continuously alongside database, server, and shard-health metrics. section 6.6
- Define a threshold that flags lag as an anomaly requiring attention. section 6.6
- Trigger responses such as rerouting traffic away from a slow server, scaling resources, or reassigning overloaded shards. section 6.6
- Log automated actions through incident-management tools so engineers can review them when necessary. section 6.6
Table 6.6 Data replication, sharding, and partitioning
|
Topic
|
Fundamentals
|
Applied skills
|
Advanced
|
|
Data replication
|
Understand that data is copied across nodes to improve availability and fault tolerance.
|
Use leader-follower or multi-leader replication. Tune sync vs. async replication. Handle stale reads and conflicts.
|
Optimize replication lag, implement quorum reads/writes, and reason about consistency in geo-replicated systems.
|
|
Sharding (horizontally partitioning)
|
Understand that data is split across multiple databases or nodes, usually by key.
|
Implement horizontal scaling using range-based or hash-based sharding. Handle rebalancing and routing logic.
|
Design for cross-shard transactions, hotspot detection, and dynamic resharding without downtime.
|
|
Partitioning
|
Know that partitioning divides data into independent subsets for manageability and parallelism.
|
Apply vertical vs. horizontal partitioning. Use partitioning to reduce query latency and contention.
|
Design partition-aware data models and query strategies. Handle skew, repartitioning, and partition pruning at scale.
|
Use the comparison table to place replication lag within replication strategies, stale reads, conflicts, quorum reads and writes, and consistency in geo-replicated systems. section 6.5
A concise explanation should connect the metric to availability, consistency, latency, observability, and automated remediation. section 6.5 section 6.6





