Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Hard Production Scenario

How do you troubleshoot and fix MySQL Replication Lag in Master-Replica setups?

Real-World Scenario / Incident Description

Replica lag jumped to 3,600 seconds on a secondary reader server during nightly report generation.

687 views • Updated 1 month ago

Key Fixes for Replication Lag

  1. Enable Multi-Threaded Slaves (MTS):
    slave_parallel_workers = 16
    slave_parallel_type = LOGICAL_CLOCK
    
  2. Eliminate Huge Single-Query Writes: Break massive 5-million-row DELETE or UPDATE statements into chunks of 5,000.
  3. Disable Sync Binlog on Replicas: Set sync_binlog = 0 and innodb_flush_log_at_trx_commit = 2 on read replicas.
Related Concepts: #Replication Lag #Multi-Threaded Slave #High Availability