Replication Lag
Replication lag is the delay between a write on the primary and its appearance on the replica. Monitor with Seconds_Behind_Source.
Replication lag is the delay between a write on the primary and its appearance on the replica. Monitor with Seconds_Behind_Source.
-- Check lag on replica
SHOW REPLICA STATUS\G -- Seconds_Behind_Source
-- Causes of lag:
-- 1. Long transactions on primary
-- 2. Network latency
-- 3. Heavy read load on replica competing with SQL thread
-- Reduce lag with parallel replication (MySQL 5.7+):
-- slave_parallel_workers = 4
-- slave_parallel_type = LOGICAL_CLOCK
-- Monitor in MySQL 8:
SELECT * FROM performance_schema.replication_applier_status_by_worker;
Alert when Seconds_Behind_Source > 30 — it means reads from replica return stale data.