Skip to content
RED SAGSkills
mediumDatabase Administrator interview question

How do you set up and monitor replication, and what do you do when replica lag grows?

What the interviewer wants to hear

  • Streaming or binlog replication from primary to replicas
  • Measure lag in bytes and time
  • Use pg_stat_replication or SHOW REPLICA STATUS
  • Common causes: heavy writes, slow replica disk, long queries on replica, network
  • Alert on thresholds and route reads carefully

Model answer

In PostgreSQL I use physical streaming replication, where replicas receive WAL from the primary; in MySQL, binlog replication, ideally with GTIDs. For monitoring I track lag in both bytes and time. In PostgreSQL pg_stat_replication shows write_lag, flush_lag and replay_lag; in MySQL SHOW REPLICA STATUS shows Seconds_Behind_Source, though a heartbeat table is more reliable. I export these to Prometheus and alert on thresholds. When lag grows I look for the cause: a big batch job or index build on the primary, a slow disk or weaker instance on the replica, long-running queries on the replica conflicting with replay, or network limits. Fixes include breaking big jobs into batches, upgrading replica hardware, enabling parallel apply in MySQL, and making the app stop reading from replicas that lag too much.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Database Administrator questions