Asynchronous replication trades durability for throughput — a primary that crashes between commit and binlog ship loses the transactions in flight. Semi-synchronous replication closes that gap: a transaction does not return success to the client until at least one replica has acknowledged receipt of the binlog event. This article is the production configuration we deploy when a client cannot tolerate the data-loss window of pure async, what the tuning knobs really do, and the operational notes that decide whether semi-sync helps or hurts.
How to verify
Semi-sync’s status is in two places — the global variables that show it is enabled, and the status counters that confirm replicas are acknowledging.
mysql -e "SHOW VARIABLES LIKE 'rpl_semi_sync%';"
mysql -e "SHOW STATUS LIKE 'Rpl_semi_sync%';"
mysql -e "SELECT * FROM performance_schema.replication_connection_status;"
mysql -e "SHOW PLUGINS;" | grep -i semi
On the primary, Rpl_semi_sync_source_status (or Rpl_semi_sync_master_status on older versions) reads ON when at least one replica is acknowledging. Rpl_semi_sync_source_yes_tx and Rpl_semi_sync_source_no_tx show how many commits were semi-sync-ack’d vs fell back to async after timeout.
What’s happening
Semi-sync inserts an acknowledgement step into the commit path. After the primary writes the binlog event, it waits for at least rpl_semi_sync_source_wait_for_slave_count replicas to confirm receipt before the client sees OK. The replica acknowledges as soon as the event is in its relay log on disk — not after it is applied. That distinction matters: semi-sync guarantees no data loss on primary crash, not that the replica has caught up with the data.
There are two modes. AFTER_SYNC is the production default and what the variable name suggests — the primary syncs the binlog to disk and ships it, then waits for ack before committing in the storage engine. AFTER_COMMIT commits in InnoDB first, then ships and waits. AFTER_SYNC is safer (no phantom reads of half-committed data on the primary if it crashes between commit and ship); AFTER_COMMIT lets the primary read its own writes a hair faster.
If the replica is slow or down, the primary waits up to rpl_semi_sync_source_timeout milliseconds (default 10000 = 10s), then falls back to async for that transaction and every subsequent one until a replica reconnects. Semi-sync is not a guarantee against the primary stalling — it is a guarantee against silent data loss when at least one replica is responsive.
In MySQL 8.0.26+, the plugin and variable names migrated from master/slave to source/replica. Older deployments still use rpl_semi_sync_master_*. The behaviour is unchanged.
The procedure
-
Install the plugin on the primary and on every replica. The plugins are separate — one for the primary side, one for the replica side.
-- on the primary INSTALL PLUGIN rpl_semi_sync_source SONAME 'semisync_source.so'; -- on each replica INSTALL PLUGIN rpl_semi_sync_replica SONAME 'semisync_replica.so';Confirm with
SHOW PLUGINS;and check both rows areACTIVE. -
Set the variables on the primary in
my.cnfso they survive restart.[mysqld] plugin_load_add = semisync_source.so rpl_semi_sync_source_enabled = 1 rpl_semi_sync_source_timeout = 5000 rpl_semi_sync_source_wait_for_slave_count = 1 rpl_semi_sync_source_wait_point = AFTER_SYNC -
Set the variables on every replica.
[mysqld] plugin_load_add = semisync_replica.so rpl_semi_sync_replica_enabled = 1 -
Restart the replication IO thread on each replica to pick up the new mode.
STOP REPLICA IO_THREAD; START REPLICA IO_THREAD; -
Verify the handshake. The status on the primary should show
ON, and the replica’s status row should match.SHOW STATUS LIKE 'Rpl_semi_sync_source_status'; SHOW STATUS LIKE 'Rpl_semi_sync_source_clients'; SHOW STATUS LIKE 'Rpl_semi_sync_replica_status'; -
Test fallback. Stop the replica’s IO thread on every replica, then commit a transaction on the primary. The first commit waits up to
rpl_semi_sync_source_timeoutms, then falls back;Rpl_semi_sync_source_no_txincrements.-- on every replica STOP REPLICA IO_THREAD; -- on the primary INSERT INTO test.semi VALUES(NOW()); SHOW STATUS LIKE 'Rpl_semi_sync_source_status'; -- now OFF SHOW STATUS LIKE 'Rpl_semi_sync_source_no_tx'; -
Restore the replicas and confirm semi-sync re-engages.
START REPLICA IO_THREAD; -- on the primary, wait a beat, then SHOW STATUS LIKE 'Rpl_semi_sync_source_status'; -- ON again
Common pitfalls
- Treating semi-sync as synchronous — it is not. Replicas acknowledge after relay-log write, not after apply. A replica can be behind in apply by hours while continuing to acknowledge in semi-sync.
rpl_semi_sync_source_timeouttoo low — a network blip pushes every transaction into async fallback. Too high and the primary stalls when a replica freezes. We default to 5s and tune from there based on observed network latency.- One-replica
wait_for_slave_count=1with that replica down — the primary serves writes as plain async; the durability claim is gone. For two-of-three durability, setwait_for_slave_count=2with three replicas — but understand that two replica failures will stall writes. AFTER_COMMITin production — the primary can read data the replicas have not received; a primary crash at that instant means the application has read records that do not survive. UseAFTER_SYNCunless you have a measured reason.- Plugin name mismatch on upgrade — MySQL 8.0.26+ renamed the plugins (
semisync_source/semisync_replica); older config blocks referencingsemisync_master/semisync_slavesilently fail to load on a newer build.
Semi-sync replication is the right choice when the cost of losing the last few transactions on a crash exceeds the cost of the modest latency hit on commit. In the engagements we run, we deploy semi-sync on primary-replica topologies where the application’s data-loss tolerance is zero seconds — financial ledgers, audit trails — and pair it with GTID-based replication and explicit failover playbooks. For the broader pattern of operating replicated MySQL with strict durability, see /en/solutions/clustered-environments/.