A read-replica at zero lag for months suddenly reports Seconds_Behind_Source: 90 and stays there. Reports go stale, dashboards drift, and someone asks if you should fail over. Don’t. The number can blow up because the network is congested, because the IO thread can’t keep up with binlog volume, because the SQL thread is stuck on a slow statement, or because a long transaction is being replayed in full. Each has a different fix.
What’s happening
Classic MySQL replication has two threads on the replica: the IO thread pulls binary log events into a relay log on local disk, and the SQL thread reads the relay log and applies the events. If the IO thread falls behind, you are network or disk bound. If the IO thread is current but the SQL thread is behind, you are CPU or lock bound. Until MySQL 5.7 the SQL thread was single-threaded by default, so one slow DELETE against an unindexed column on the primary stalls the replica while primary writes keep flowing. Parallel replication (replica_parallel_workers) helps, but only for workloads that can be parallelized by schema or transaction group.
How to verify
Start with the obvious view:
SHOW REPLICA STATUS\G
Read four fields in order. Seconds_Behind_Source is the symptom. Replica_IO_Running and Replica_SQL_Running both need to be Yes. Compare Read_Source_Log_Pos against the primary’s current binlog position — if the read position is far behind, the IO thread is the bottleneck. If the read position is current but Exec_Source_Log_Pos is far behind, the SQL thread is.
Inspect what each thread is doing:
SELECT thread_id, name, processlist_state, processlist_time
FROM performance_schema.threads
WHERE name LIKE 'thread/sql/replica%';
A processlist_state stuck on Waiting for table metadata lock or Updating for hundreds of seconds is your slow statement. To find it, grab the current relay log event:
SELECT * FROM performance_schema.replication_applier_status_by_worker\G
If you suspect network, check Source_Heartbeat_Period and watch whether the IO thread reconnects in the error log. A flapping IO thread is a network or auth issue.
The fix
If the IO thread is behind, raise slave_compressed_protocol or move the replica to a closer region — replication compression is cheap, cross-region replication over a saturated link is not. If the SQL thread is the bottleneck on MySQL 8, enable parallel replication:
STOP REPLICA SQL_THREAD;
SET GLOBAL replica_parallel_type = 'LOGICAL_CLOCK';
SET GLOBAL replica_parallel_workers = 8;
START REPLICA SQL_THREAD;
If a single offending statement is replaying, the real fix is on the primary — that DELETE or UPDATE needs an index or to be batched. Replaying it faster on the replica just postpones the next event. Don’t reach for failover unless replica freshness is breaking a customer commitment; the lag will catch up once the offending event finishes.
Replica lag that recurs every week is a workload pattern, not a one-off. Stack Harbor’s Managed Cloud Ops covers the ongoing tuning that keeps replicas honest — start a conversation.