Scrivio Interview library
DesignAdvanced8 min read · updated 12 November 2026

Your team runs its own failover scripts for MySQL using a two-node setup with a health check from a third server. Explain why this design is prone to split brain and propose a safer architecture.

A two-node setup with a single health-check server has no reliable majority: when the network splits, the observer can only see symptoms such as timeouts, and the old primary may still be alive and taking writes while the replica is promoted. A safer design uses at least three voting members so every failover needs a quorum, fences the old primary (super_read_only and cut routing) before promoting, and relies on a proven tool such as InnoDB Cluster or Orchestrator with Raft instead of custom scripts.

Why this question is asked

Home-grown failover scripts are common because they look simple: check the primary, and if it does not answer, promote the replica. They work in every test where the primary is cleanly switched off, and they fail on the day the network misbehaves. Interviewers ask this question at senior level because the answer shows whether we see failover as a distributed systems problem rather than a scripting task. In this answer, we will recap what split brain is, walk through the exact failure in the two-node design, see why health checks cannot tell the truth, and then build a safer architecture with quorum, fencing and proven tooling.

1A Quick Recap of Split Brain

Split brain is the state where two database servers both believe they are the primary and both accept writes. Each side then holds changes the other does not know about. When the network heals, there is no automatic way to merge them: an order may exist on one side, a payment on the other, and the same auto-increment id may have been handed out twice.

In MySQL replication, the primary writes changes to its binary log and replicas apply them. A replica that is promoted stops applying and starts accepting writes. If the old primary is still running and some application servers can still reach it, we now have two primaries. The longer it lasts, the more data must be reconciled by hand, and some of it may be lost for good.

2How the Two-Node Design Splits

Picture the setup: db1 is the primary, db2 is the replica, and a third server, the monitor, runs a script every few seconds that connects to db1. If db1 fails three checks in a row, the script runs STOP REPLICA and sets read_only=0 on db2, then changes a DNS record or a virtual IP to point at db2.

Now suppose the network link between the monitor's rack and db1's rack drops for 40 seconds. The monitor cannot reach db1, so it promotes db2. But db1 is healthy, and the application servers in db1's rack can still reach it, so they keep writing there. The DNS change takes time to reach every client, and connection pools keep their existing connections to db1 anyway. For those 40 seconds, and often longer, both servers accept writes.

Step throughA partition that creates two primaries
App serversdb1 (primary)Monitordb2 (replica)
health check times out (link down)
second and third checks time out
STOP REPLICA; SET read_only = 0
move DNS / VIP to db2
writes continue on pooled connections
new connections write here
no replication: two divergent histories

7 messages in order. Play them, or step through them one at a time.

The monitor saw a timeout, not a dead server. db1 never learned it had been replaced.

Notice the core problem: the decision was made by one observer, and that observer was itself on one side of the partition. With two database nodes and one monitor, there is no group of members that can say 'we are the majority, so we decide'. Each part of the system acts on its own partial view, and each can conclude that it is in charge.

3Why Health Checks See Symptoms, Not the Truth

A health check can only observe that a request did not get an answer in time. That symptom has many causes: the server crashed, the server is overloaded by a long query or a backup, a switch is dropping packets, the monitor's own network is broken, or a garbage collection pause in the monitor itself delayed its timer. From the outside, a slow primary looks exactly like a dead one.

This is why tuning the timeout never fully fixes the design. A short timeout promotes on every hiccup and causes needless failovers. A long timeout makes real outages longer. Neither one gives the monitor knowledge it does not have, which is whether the old primary can still accept writes from somebody. Only two things make the decision safe: a majority vote, so a minority side cannot act, and fencing, so the old primary is stopped even if it is alive.

4Use at Least Three Voting Members

Quorum means a decision needs a majority of the voting members. With three members, two must agree; with five, three must agree. During a partition, at most one side can have a majority, so at most one side can elect a primary. The minority side knows it is in the minority and stops accepting writes.

For MySQL there are mature ways to get this. MySQL Group Replication, packaged with MySQL Router and MySQL Shell as InnoDB Cluster, runs a Paxos-based group of three or more servers; a member that loses contact with the majority stops accepting writes, and the group elects a new primary only with a quorum. Orchestrator can run with a Raft backend across three or more Orchestrator nodes, so the failover decision itself needs a majority of observers placed in different zones. Managed services such as Amazon RDS Multi-AZ or Aurora, Cloud SQL and Azure Database for MySQL build this in.

Two-node script versus a quorum design
SituationTwo nodes + monitor scriptThree voting members
Network splits monitor from primaryPromotes replica; old primary keeps writingMinority side stops writes; majority elects one primary
Primary slow for 20 secondsLooks dead, may be promotedGroup detects suspicion by vote, not one timer
Monitor server failsNo failover at allRemaining members still decide
Who decides?One observer with a partial viewA majority of members
Quorum does not make failures rarer; it makes sure only one side can act on them.

The placement matters as much as the count. Three members in the same rack are still one failure domain. We spread them across three availability zones or racks, so the loss of any one location still leaves a majority.

5Fence the Old Primary Before Promoting

Even with a quorum, we want a second safety net. Fencing means actively preventing the old primary from accepting writes before the new one takes over. In MySQL the database-level fence is SET GLOBAL super_read_only = ON, which also blocks users with administrative privileges, unlike plain read_only. The routing-level fence is to remove the old primary from the proxy (ProxySQL, MySQL Router or a load balancer) or withdraw its virtual IP, so clients cannot reach it.

SQL
-- On the old primary, if it is reachable
SET GLOBAL super_read_only = ON; -- writes now fail, even for admin users
SELECT @@super_read_only; -- 1
-- On the new primary, only after the fence succeeded
STOP REPLICA;
SET GLOBAL super_read_only = OFF;
SET GLOBAL read_only = OFF;
SELECT @@read_only; -- 0: accepts writes

But there is a catch: if the old primary is unreachable, we cannot send it a command. That is exactly the case where the old primary might still be alive. So the fence must not depend only on talking to it. Cutting it out of the routing layer, using a lease that expires on the old primary when it loses the quorum, or in the extreme powering it off through an out-of-band interface (this is the classic STONITH idea, shoot the other node in the head) are ways to fence without its cooperation. The rule is simple: no promotion until we are sure the old primary can no longer take writes.

6A Safer Architecture, and How to Prove It

Putting this together, the design I would propose is three MySQL servers in three zones running InnoDB Cluster in single-primary mode, MySQL Router or ProxySQL on the application side so clients follow the elected primary automatically, and Spring Boot applications configured with short connection lifetimes so pools do not hold connections to a demoted server for long. If the team prefers classic asynchronous replication, Orchestrator with a Raft backend over three nodes plus a routing fence is a reasonable alternative. If the organisation is in a cloud, a managed database service removes most of this work and is often the best answer.

The last part is proof. A failover design is only as good as the failures it has survived in practice. We drill partitions in staging: drop traffic between zones with firewall rules, freeze the primary with a long lock or by pausing the process, kill the monitor nodes, and check after each drill that exactly one primary accepted writes and no committed transaction was lost. Running these drills on a schedule, not once, keeps the design honest as versions and networks change.

Step throughSafe failover decision
  1. Primary suspectedmissed heartbeats from several members
  2. Majority agrees it is unreachable?
    YesContinue to fencingNoDo nothing; minority cannot act
  3. Fence the old primarysuper_read_only, remove from router, lease expiry
  4. Fence confirmed?
    YesPromote the most up-to-date replicaNoStop and page a human
  5. Repoint routingrouter or proxy follows the new primary

5 steps in order. Play them, or step through them one at a time.

Two gates protect the promotion: a quorum and a confirmed fence.

7Follow-up questions

Why not just add a second monitor server?

Two monitors can disagree with each other, and then we need a rule for who wins, which brings back the same problem. What we need is an odd number of voters, at least three, that reach a majority decision, and that is exactly what Raft or Paxos based tools give us. Adding observers without a voting protocol only adds more partial views.

Is semi-synchronous replication enough to prevent split brain?

No. Semi-synchronous replication makes the primary wait until at least one replica has received a transaction before acknowledging the commit, which reduces data loss on failover. It does not decide who is primary and does not stop an old primary from accepting writes during a partition. It solves durability, not leadership.

What about the applications during a failover?

They will see errors for some seconds. Spring Boot applications should retry idempotent operations, use a router or proxy address rather than a fixed host, and set a maximum connection lifetime in HikariCP so pooled connections to the old primary are replaced. Writes that failed must be retried by the caller or reported, never silently dropped.

8Conclusion

In this answer, we saw why two database nodes and a single health-check server are prone to split brain: the observer can be partitioned too, and a timeout cannot distinguish a slow primary from a dead one. A safer design uses at least three voting members across failure domains so only a majority can elect a primary, fences the old primary with super_read_only and routing changes before promoting, prefers InnoDB Cluster, Orchestrator with Raft or a managed service over custom scripts, and proves all of it with regular partition drills.

What to say in the interviewAbout 90 seconds aloud

Open with

The problem with this design is that there is no reliable majority. We have two database nodes and one observer, and the observer can be on the wrong side of a network partition.

Then, if they want more

If it loses contact with the primary, it promotes the replica, but the old primary may be perfectly healthy and still reachable by some application servers, so both sides accept writes and the data diverges.

A health check also only sees symptoms: a timeout looks the same whether the primary crashed, is overloaded, or the monitor's own network is broken, so a slow primary looks dead.

What I would propose instead is at least three voting members in three zones, for example MySQL InnoDB Cluster with Group Replication, or Orchestrator with a Raft backend if we stay on asynchronous replication, so a failover needs a quorum and a minority side cannot act.

Before promoting, the system fences the old primary: super_read_only on, removed from the router or proxy, or a lease that expires, and if the fence cannot be confirmed it stops and pages a human. Clients connect through MySQL Router or ProxySQL so they follow the new primary.

Honestly, if we are in a cloud, a managed service is usually the better choice than maintaining scripts. Whatever we pick, we drill partitions and frozen primaries in staging regularly and check that only one primary ever took writes.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your team runs its own failover scripts for MySQL using a two-node setup with a health...": https://scrivio-interview-library.netlify.app/databases/replication-and-ha/80b89f3ca8/