0
0
MysqlConceptBeginner · 3 min read

Semi Synchronous Replication in MySQL: What It Is and How It Works

In MySQL, semi synchronous replication is a replication method where the master waits for at least one slave to confirm it received the transaction before committing. This ensures better data safety than asynchronous replication without the full delay of synchronous replication.
⚙️

How It Works

Semi synchronous replication in MySQL works like a middle ground between fully synchronous and asynchronous replication. Imagine you send a letter (transaction) to a friend (slave). Instead of waiting for your friend to read and reply (fully synchronous), you just wait until they confirm they got the letter (semi synchronous). This confirmation means the data is safely copied to at least one slave before the master moves on.

This method reduces the risk of data loss if the master crashes because it knows at least one slave has the latest data. However, it doesn't wait for all slaves to confirm, so it is faster than full synchronous replication. The master sends the transaction, waits for one slave's acknowledgment, then commits the transaction.

💻

Example

This example shows how to enable semi synchronous replication on the master and a slave in MySQL. It configures the master to wait for one slave to acknowledge before committing.
sql
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

-- On Master:
SET GLOBAL rpl_semi_sync_master_enabled = 1;

-- On Slave:
SET GLOBAL rpl_semi_sync_slave_enabled = 1;

-- Check status on Master:
SHOW STATUS LIKE 'Rpl_semi_sync_master_status';
Output
+------------------------------+-------+ | Variable_name | Value | +------------------------------+-------+ | Rpl_semi_sync_master_status | ON | +------------------------------+-------+
🎯

When to Use

Semi synchronous replication is useful when you want better data safety than asynchronous replication but cannot afford the full delay of synchronous replication. It is ideal for systems where losing a few transactions is risky but some delay is acceptable.

For example, in financial applications or online stores, you want to ensure transactions are copied to at least one backup server before confirming success to the user. This reduces data loss risk if the master fails suddenly.

It is also helpful in geographically distributed setups where waiting for all slaves would cause too much delay.

Key Points

  • Semi synchronous replication waits for one slave to confirm receipt before master commits.
  • It balances data safety and performance better than fully synchronous or asynchronous replication.
  • Requires enabling plugins on both master and slave servers.
  • Useful for critical data where some delay is acceptable but data loss is not.

Key Takeaways

Semi synchronous replication ensures at least one slave confirms receipt before master commits.
It improves data safety without the full delay of synchronous replication.
Enable semi sync plugins on both master and slave to use this feature.
Ideal for applications needing a balance between performance and data reliability.