Neki, sharded Postgres, is now available. Learn more
Navigation

Blog|Engineering

MySQL semi-sync replication: durability consistency and split brains

Shlomi Noach |

Updated September 2026 for MySQL 8.0 and 8.4.

MySQL semi-sync is a plugin mechanism on top of asynchronous replication, that can offer better durability and even consistency (term defined later). It helps in high availability solutions, but can in itself reduce availability. Semi-sync replication makes MySQL writes durable, but it doesn't prevent split brain. In this post, we'll walk through the failure scenarios, replica placement choices, and quorum tradeoffs, updated for MySQL 8.0+.

I recommend reading this semi-sync blog post by Jean-François Gagné (aka JFG), which illustrates the internals of the semi-sync implementation, and debunks some myths about semi-sync. We will overlap a bit with another recommended post by JFG, about high availability and recovery.

How semi-sync replication works

As a quick recap, semi-synchronous replication is a mechanism where a commit on the primary does not apply the change onto internal table data and does not respond to the user, until the changelog is guaranteed to have been persisted (though not necessarily applied) on a preconfigured number of replicas. Everything in this post applies to MySQL 5.7 and later, including MySQL 8.0 and 8.4. We'll use the current (post-8.0.26) names for settings, with the older names noted where relevant.

Specifically, the primary is configured with rpl_semi_sync_source_wait_for_replica_count (called rpl_semi_sync_master_wait_for_slave_count before MySQL 8.0.26), which is 1 or above, if semi-sync is to be used. An INSERT transaction, for example, will not report being committed (i.e., the user will not get “OK”) until at least that number of replicas have acknowledged receipt of that transaction’s changelog (entries in the binary log). In practice, this means at least that number of replicas have written the changelog onto their relay logs where the change is now persisted. The replicas will apply the change later on, normally as soon as they can. For the scope of this post, we assume replicas are not intentionally stopped, and we can also ignore delayed replicas.

The primary waits up to rpl_semi_sync_source_timeout (formerly rpl_semi_sync_master_timeout), after which it falls back to asynchronous replication mode, committing and responding to the user even if not all expected replicas have acknowledged receipt.

What actually happens when the timeout expires?

The primary silently falls back to asynchronous replication. Commits start succeeding without any replica acknowledgement. Your application notices nothing, but the durability guarantee is gone. Once enough semi-sync replicas catch up and acknowledge again, the primary automatically switches back to semi-sync mode.

The default timeout is 10 seconds, and "silently" is the operative word: if you rely on semi-sync for durability, you must monitor the Rpl_semi_sync_source_status status variable (formerly Rpl_semi_sync_master_status) and alert when it flips to OFF. This silent fallback is why, for the rest of this post, we assume an effectively infinite timeout. A durability guarantee that evaporates under load is not much of a guarantee.

The only replicas to acknowledge receipt of the changelog are replicas where semi-sync is enabled. There could be other, non semi-sync replicas in our topology. They, too, pull the changelog from the primary, but do not acknowledge receipt. As JFG points out in his post, the semi-sync replicas aren’t necessarily the most up to date. It’s possible that a non-semi-sync replica has pulled more changelog data than some or all semi-sync replicas.

Semi-sync vs. asynchronous replication: what are you trading?

In asynchronous replication, MySQL's default, the primary commits a transaction and responds to the client immediately. Replicas pull the changelog on their own schedule. Writes are as fast as the primary itself. The cost: if the primary crashes, its most recent commits may not exist on any other server. Your application was told "OK," and the data is gone.

Semi-sync inserts exactly one guarantee into that flow: the primary will not confirm a commit to the client until the changelog for that transaction is persisted on at least rpl_semi_sync_source_wait_for_replica_count replicas. In exchange, every write now pays a network round trip to the fastest acknowledging replica(s), and your ability to take writes depends on enough semi-sync replicas being responsive.

In short: asynchronous replication risks losing acknowledged data on a primary crash; semi-sync removes that risk for the price of write latency and an availability dependency. Neither one prevents split brain. That requires intervention at a higher layer, as the rest of this post shows.

Does semi-sync guarantee durability?

The most straightforward use case for semi-sync is to guarantee durability of the data. We only approve a commit once the transaction (in the form of a changelog) is persisted elsewhere, on a different server, or on multiple servers.

As mentioned earlier, this does not mean the changelog has been applied on those servers. Replication may be lagging and the servers may be too busy to be able to apply the changelog in a timely fashion. But, at the very least, if the primary crashes, there’s “forensic evidence” in the relay logs of a semi-sync replica that can tell us what the latest changes were.

AFTER_SYNC vs. AFTER_COMMIT: what "lossless" semi-sync means

A setting we haven't mentioned yet controls when the primary waits for replica acknowledgement: rpl_semi_sync_source_wait_point (formerly rpl_semi_sync_master_wait_point). It has two values, and the difference matters most at the worst possible moment: when the primary crashes mid-commit.

With AFTER_SYNC, the default since MySQL 5.7, the primary writes the transaction to its binary log, syncs the log, and waits for acknowledgments from the configured number of replicas; only then does it commit the transaction to the storage engine and return success to the client. During the wait, a replica may already have received and applied the transaction, while the primary has not committed it or made it visible to other sessions; if the primary crashes then, the client may not know whether the transaction took effect, since a promoted replica may have it or may not. The guarantee is that transactions committed on the primary have been acknowledged by the required number of replicas, which is the sense in which AFTER_SYNC is called lossless semi-sync: it protects committed transactions, but cannot tell a client the outcome of an interrupted commit.

With AFTER_COMMIT (the older behavior, from MySQL 5.6), the primary commits locally first, then waits for acknowledgement, then responds to the client. That opens an ugly window: the transaction is committed and visible on the primary, other sessions may have already read that data, but no replica has it yet. If the primary crashes in that window and you fail over, you've lost data that other transactions may have already acted upon.

If you take one configuration detail away from this post, it's this: use AFTER_SYNC unless you have a very specific reason not to.

What does "consistent" mean during a failover?

The term “consistency” is overloaded, and especially in distributed systems. The CAP Theorem definition of consistency is, for example, very strict: once data was written on one server, any immediate follow-up read on any other server must reflect that write (or any later write).

We will suffice with eventual consistency. This in itself is an overloaded term, so let’s clarify: in the case of a primary outage, we consider our system consistent if we’re able to promote a new primary within any amount of time (in practice, we expect the time to be short) such that it is consistent with the previous primary’s advertised state. I write “advertised” state because the end user or applications should not be surprised by any data changes when the new primary is promoted, regardless of how transactions/replication work internally.

What is a split brain, and does semi-sync prevent it?

No. This surprises people: semi-sync on its own does not prevent split brain, and later in this post, we'll walk through exactly how one happens in a semi-sync topology.

A split brain is a situation where there are two servers which are simultaneously taking writes, each thinking they’re the (single) primary. In a split brain scenario, the data diverges between the two servers. If those servers also have replicas, then we have two divergent replication trees. Fixing and merging those divergent trees is difficult, and normally, we revert the changes on one to make it look like the other (whether by backup+restore or by some rollback method).

Reiterating JFG’s observation, while engineers normally frown upon split brains, the damage of split brain may well be within a product’s allowance.

Topologies and scenarios

As always, getting best durability as possible, best consistency as possible, best response times as possible, best split brain mitigation as possible, is costly. Product owners and engineers make reasonable tradeoffs.

How many semi-sync replicas do you need?

The rule of thumb falls out of the failure math: rpl_semi_sync_source_wait_for_replica_count should equal the number of simultaneous server losses you want to survive with certainty. With a wait count of 1, you can lose the primary alone and be fine. But if the primary and one semi-sync replica go down together (say, a shared rack or availability zone fails), you can no longer be sure any surviving replica has the latest acknowledged writes. A wait count of 2 survives losing the primary plus one replica, at the cost of higher write latency, since every commit now waits for the second-fastest acknowledgement.

Count is only half the decision; placement is the other half. Acknowledgements from a replica in the same datacenter as the primary are fast but protect you least. The failures that take out your primary (power, network, cooling) have higher likelihood of taking out its neighbors too. The sections below walk through what each placement choice actually buys you when things fail.

Let’s consider a few configured topologies, and see what scenarios we can expect upon failure. In particular, we'll look at how durable our data is, if we can expect it to be consistent, and if we can expect split brains.

General scenario: wait for single replica, multiple semi-sync replicas

In this common scenario, our primary is configured with rpl_semi_sync_source_wait_for_replica_count=1, and there are multiple (more than one) replicas configured with semi-sync. Let’s say there are 4 semi-sync replicas, named R1, R2, R3, and R4. We nickname this setup “1-n.”

In this setup, a write takes place on the primary, and before approving the write to the user/app, the primary waits for an acknowledgement from exactly one replica. It doesn’t matter which. For some writes, it will be replica R1; at some other time, R4 is the first to acknowledge.

It’s important to note that the changelog, the binary log, is sequential. A replica that acknowledges some changelog event has necessarily received all of its prior events. This is why the primary doesn’t need to care that different acknowledgements come from different replicas. An acknowledgement means there’s a replica with full durability of committed transactions up to and including the one in question.

Should the primary fail, we have at least one replica guaranteed to have all approved commits in its relay logs. These are not necessarily applied, but if our replication cluster is normally low-lagged, we can expect those commits to be few, and we can expect the replica to catch up (apply those commits) within a few seconds or less.

A possible situation is that there may be non-semi-sync replicas even more up to date than our semi-sync replica. We can choose to use them. The fact that they have more transactions than the most up-to-date semi-sync replica means they have received binary log events not acknowledged by a semi-sync replica. While this may seem confusing at first, these are fine to accept, and do not contradict our promise to our users. We promised that “if the primary tells you a commit is successful, then the data is durable elsewhere”. We never said anything about the state of the data before telling the user the commit is successful. In fact, this scenario is no different than the primary actually getting a commit acknowledged by the replica, beginning to communicate that to the user, then crashing halfway. The user cannot distinguish between the two cases at the time of failure (though post-crash analysis may indicate which of the two was true).

And so we can choose to use the data from that even-more-up-to-date non-semi-sync replica, seed the rest of the replicas with that data, or, we can choose to throw away any server that is more-up-to-date than our most-up-to-date semi-sync replica and recycle them. It’s our choice and it’s down to operational considerations (time, capacity, load...).

If data is durable, does that mean it’s available?

Not necessarily. Consider this possible, even likely scenario: the primary and R1 are both in the same data center. R2, R3, R4 are in different availability zones, possibly remote, and so have higher latency than R1 communicating to the primary.

The app issues an UPDATE on the primary. R1 acknowledges the write. R2, R3, R4 do not, as yet. But the primary does not care. It commits and reports success to the app. Then the primary and R1 both get network isolated together because the DC they’re in has lost network. The loss of network cut short the delivery of the change log to R2, R3, R4. They never got it.

Should we promote either R2, R3, or R4, we lose consistency. The app expects the result of that UPDATE to be there, but neither of these servers have the data. Moreover, even human intervention is limited. Since the data is only found on primary and R1, we cannot get hold of the data. A human can always transport to the physical server to extract the data and send it over via cellular network, or even by car. It’s likely that this will take substantial time.

A predefined failover plan may choose to promote, say, R2, after all, losing some data, but cutting short on outage time. Reconciliation will have to take place afterwards.

After a failure, how do you know which replica is safe to promote?

If the primary and one of the semi-sync replicas go offline, we have an additional problem: we can’t say for sure whether any of the remaining semi-sync replicas got the latest updates from the primary. It’s possible that they did. But it’s also possible that the single semi-sync replica that went offline, was the single one to get and acknowledge some last writes taking place on the primary.

To generalize, if the number of lost semi-sync replicas is equal to or greater than rpl_semi_sync_source_wait_for_replica_count, then we do not know whether the remaining replicas are consistent.

How a split brain happens even with semi-sync enabled

But, arguably worse, is that we can now be in a split brain situation. Apps in the primary datacenter were still writing to the old primary when the network went down. Those writes continued to run. The old primary now receives writes never seen by R2 (the newly promoted primary). Once we do wish to reconcile, we are faced with contradicting information.

Where should you place semi-sync replicas: same datacenter or cross-datacenter?

The geo-distribution of our servers plays a key part in how tolerant our system is for failure and what outcomes we can expect.

Colocated primary and semi-sync replicas

On a normal day, writes to the primary have low latency: acknowledgements from semi-sync replicas are quick to arrive thanks to the fast network within a datacenter.

When the primary fails, we have at least one good semi-sync replica to promote (or we can use it to seed a different server to promote). Because we promote within the same datacenter, app behavior is unlikely to be affected, other than the obvious disruption during the failover time.

If the datacenter is network-isolated, we need to make a decision: wait out the outage, incurring downtime to our services, or promote a new primary in another datacenter. We risk losing transactions (we cannot know whether we lose transactions until we are again able to connect to the original primary). We also risk a split brain scenario.

Cross-site semi-sync replication

If we only run semi-sync replicas in a different datacenter than the primary’s, we first pay with increased write latency, as each commit runs a roundtrip outside the primary’s datacenter and back. With multiple semi-sync replicas, it’s the time it takes for the fastest replica to respond.

When the primary goes down, we have the data durable outside its datacenter. But we can then also compare with non semi-sync replicas in the primary’s datacenter: they may yet have all the transactions, too, in which case we can promote one of them. Again, promoting within the same datacenter tends to be less disruptive to the application.

Or, we can choose to promote our semi-sync replicas, switching the primary data center for the replication cluster. We then must reassign semi-sync replicas, and ensure none run from within the new primary’s datacenter.

In the event of the primary’s datacenter network isolation, we promote one of our semi-sync replicas, in a different DC. We reconfigure semi-sync replicas, before making the new primary writable. This avoids a split brain scenario, assuming all of our semi-sync replicas are available to us.

What if two or more sites get network isolated at the same time?

It largely depends on your hardware distribution.

If your servers are distributed across three sites, then the majority of your sites is now down. Chances are you were only planning for single site outage at any given time, and a two-site outage is a hard downtime for you. You may or may not have the capacity to run with just one-third of your hardware. You’d need to risk consistency and split brain.

Let’s assume we run out of 5 different sites (or availability zones), and 2 are down. In our “1-n” setup, split brain is still possible, even though the majority of sites is up. That’s because our semi-sync setup is about the communication between a primary and any of its replicas.

But this is also something you can attach a number to. What is the probability of two availability zones going down at the same time? For a given vendor? Across vendors? Is there a number you’re willing to accept? What is the probability of the two zones being in outage both over X minutes? Will you be willing to wait out X minutes to maintain durability and consistency?

In our physical world, there is no hard limitation to how many sites could go down at the same time. We’re generally willing to accept that some risks are so low that we can live with them.

Why semi-sync's two-server "quorum" is the root of the problem

Of special interest is that in our “1-n” scenario, we have a quorum of two servers out of five or more. The primary, with a single additional replica, is able to form a quorum and accept writes. That’s how we got to have a split brain. While R2, R3, R4 form a majority of the servers, writes took place without their agreement.

People familiar with Paxos and Raft consensus protocols may find this baffling. However, reliable minority consensus is achievable, and Sugu Sougoumarane’s Consensus Algorithms series of posts continues to describe this.

Frequently asked questions

Does semi-sync replication prevent data loss?

For acknowledged commits, yes, provided you use AFTER_SYNC and at least one replica that acknowledged the write survives the failure. It does not protect writes made after a silent fallback to asynchronous mode, which is why monitoring the semi-sync status variable is essential.

Does semi-sync prevent split brain?

No. Semi-sync only requires acknowledgement from some replica, not a majority of servers. An isolated primary plus one nearby replica can keep accepting writes while the rest of the topology promotes a new primary. Preventing split brain requires majority-based consensus or fencing above MySQL.

Is semi-sync the same as synchronous replication?

No. Replicas acknowledge that they've persisted the changelog, not that they've applied it. A semi-sync replica can acknowledge a write and still serve stale reads for a moment afterward.

What happens when the semi-sync timeout expires?

The primary silently falls back to asynchronous replication and keeps committing without acknowledgements. It returns to semi-sync automatically once enough replicas catch up. Your application sees nothing either way.

How many semi-sync replicas should I have?

Set the wait count to the number of simultaneous server losses you must survive with certainty, and place acknowledging replicas so that a single datacenter or availability-zone failure can't take out the primary and all of its acknowledgers at once.