Standard MySQL async replication can lose committed transactions during failover. Semi-synchronous replication adds a durability guarantee: at least one replica must acknowledge each transaction before the primary commits. Here is how to enable and tune it.
How Semi-Sync Works
With async replication, the primary commits and moves on — replicas apply changes later. With semi-sync, the primary waits for an ACK from at least one replica before returning success to the client. If no ACK arrives within the timeout, it falls back to async automatically.
Enable Semi-Synchronous Replication
-- On primary
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
SET GLOBAL rpl_semi_sync_master_enabled = 1;
SET GLOBAL rpl_semi_sync_master_timeout = 1000; -- ms before fallback to async
-- On each replica
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
SET GLOBAL rpl_semi_sync_slave_enabled = 1;
STOP SLAVE IO_THREAD; START SLAVE IO_THREAD; -- reconnect to activateMySQL 8.0+ Plugin Names
INSTALL PLUGIN rpl_semi_sync_source SONAME 'semisync_source.so';
INSTALL PLUGIN rpl_semi_sync_replica SONAME 'semisync_replica.so';
SET GLOBAL rpl_semi_sync_source_enabled = ON;
SET GLOBAL rpl_semi_sync_replica_enabled = ON;Monitor Semi-Sync Status
SHOW STATUS LIKE 'Rpl_semi_sync%';
-- Key metrics:
-- Rpl_semi_sync_master_status: ON = semi-sync active, OFF = degraded to async
-- Rpl_semi_sync_master_no_tx: transactions committed without semi-sync ACK
-- Rpl_semi_sync_master_yes_tx: transactions with successful ACKTuning the Timeout
The timeout controls the tradeoff between durability and latency:
- Low timeout (100ms): Falls back to async quickly, lower latency impact but less durability
- High timeout (10000ms): Waits longer for ACK, better durability but writes stall if replica is slow
-- Adjust based on your network latency between primary and replicas
SET GLOBAL rpl_semi_sync_master_timeout = 2000; -- 2 secondsSET GLOBAL rpl_semi_sync_master_wait_point = AFTER_SYNCKey Takeaways
- Semi-sync prevents data loss during primary failure at the cost of slightly higher write latency
- Use
AFTER_SYNCwait point for lossless replication - Monitor
Rpl_semi_sync_master_status— if it shows OFF, you have fallen back to async - Set a realistic timeout based on measured primary-replica network RTT
JusDB Can Help
Semi-synchronous replication is a key step toward zero-data-loss MySQL HA. JusDB can help you configure and monitor it correctly.