Can three MySQL servers agree on every commit, so losing one loses nothing?
InnoDB Cluster is MySQL's built-in answer to failover: Group Replication to keep three servers in step, MySQL Shell to set them up, and MySQL Router to send the app to whichever one is primary.
Every server fails eventually: a disk, a kernel panic, a zone outage, or just the patch you have to install on Tuesday. With one database, each of those is an outage for every customer at once. High availability turns them into a few seconds that most users never notice.
Revenue and trust. Checkout, login, payments: when the database is down, the whole product is down, and nothing in the app can work around it.
Two numbers. RTO: how fast writes work again, seconds instead of the 15 to 30 minutes a manual failover takes. RPO: how much confirmed data a failure can lose, ideally zero.
The quiet win. With a spare node, patches, upgrades and hardware swaps become rolling switchovers during the day, not maintenance windows at night.
A backup. A bad DELETE reaches every replica in milliseconds. You still need backups and point-in-time recovery.
| Availability target | Downtime allowed per year | Per month | What it takes |
|---|---|---|---|
| 99.9% ("three nines") | 8.8 hours | 43.8 minutes | One server and good backups can almost do it, if nothing big breaks. |
| 99.99% ("four nines") | 52.6 minutes | 4.4 minutes | Automatic failover. One manual 3 a.m. failover uses most of the year. |
| 99.999% ("five nines") | 5.3 minutes | 26 seconds | Automatic failover in seconds, and maintenance with no downtime at all. |
The arithmetic is why teams automate: a single manual failover at 3 a.m. can spend a whole year of a 99.99% budget.
Nobody configures a thousand clusters by hand. At that scale, high availability is a product the database team runs, with the same few parts everywhere:
Each cluster is a file in Git: size, version, replicas, settings. Terraform, Ansible or a Kubernetes operator turns the file into servers, and a pull request is how anything changes.
The same Patroni (or orchestrator, or Group Replication) setup on every cluster, so a failover at 3 a.m. behaves exactly like the one you tested.
Consul, etcd or a proxy layer tells every app where the primary is right now. Failover updates one record, not a thousand config files.
Rolling patches and upgrades one node, then one cluster, at a time. Rate limits so a bad network day cannot trigger a hundred failovers at once.
Scheduled switchovers and game days that kill a primary on purpose, restore tests from backup, and dashboards that show every cluster's role, lag and last failover.
The common incidents are scripted and safe to run; the rare ones page a person with the evidence already gathered. That is the idea behind the DBA agent on this site.
Step through it: how a team patches a cluster with no downtime.
Now let us look at how one MySQL cluster does it, starting with plain replication, then how MySQL got from manual failovers to Group Replication.
You write a row and read it back from a replica, and it is not there. Nothing was lost. The replica has not applied the change yet.
At commit, the source writes the change to the binary log. On the replica, the receiver thread copies binlog events into the relay log, and applier threads replay them. Replication is asynchronous by default: the source does not wait. Lag is how far the replica's applied data is behind the source.
For your app: read your own writes from the source. Send to replicas only the reads that can be a little stale.
replica_parallel_workers is 4 by default since 8.0.27. Busy sources often need more.Seconds_Behind_Source only covers what the replica has received. A heartbeat row updated every second shows the real lag.SHOW REPLICA STATUS\G -- 8.0.22+
SELECT worker_id, last_applied_transaction,
applying_transaction, last_error_message
FROM performance_schema.replication_applier_status_by_worker;
The same idea elsewhere: PostgreSQL shows replay_lag in pg_stat_replication. MongoDB shows it with rs.printSecondaryReplicationInfo().
| When | What changed | What it fixed, and what it did not |
|---|---|---|
| Before 5.5 | MyISAM was the default engine. | Fast reads, but no transactions, table-level locks and no crash recovery: a crash could leave tables to repair. Replication copied statements to a replica asynchronously. |
| 5.5 (2010) | InnoDB became the default engine. Semi-synchronous replication arrived. | Transactions, row locks and crash recovery from the redo log. Semi-sync made the source wait until at least one replica received each commit. |
| 2011 on | MHA, then Orchestrator (2015), scripted failover. | They found the most up-to-date replica, promoted it and re-pointed the others. Still outside MySQL, still at risk of split brain. |
| 5.6 (2013) | GTIDs: every transaction gets a global ID. | Re-pointing replicas no longer meant finding binlog file names and positions by hand. |
| 5.7.17 (2016) | Group Replication. | Servers agree on the order of every transaction before it commits. A majority must agree, so a cut-off server cannot keep writing. |
| 2017 on | InnoDB Cluster: Group Replication with MySQL Shell and MySQL Router. | Setup, failover and routing as one product, instead of three tools glued with scripts. |
Before Group Replication, a failover by hand looked like this: stop writes on the old source if it is reachable, compare Executed_Gtid_Set on each replica, pick the furthest, STOP REPLICA; RESET REPLICA ALL; and SET GLOBAL super_read_only = OFF, read_only = OFF on it, run CHANGE REPLICATION SOURCE TO ... SOURCE_AUTO_POSITION = 1 on the others, then move the app. Any transaction only the old source had was lost, or worse, came back later as a conflict.
Step through it:
With asynchronous replication, the source commits first and tells the replicas later. If it dies in between, the newest commits exist only on a dead disk, and the replica you promote never had them.
Group Replication joins three to nine servers into a group. When the primary commits, it sends the transaction to the group. The members agree on its order through a Paxos-based protocol, each one checks it for conflicts (certification), and only then does the commit return. A majority has to take part, so the transaction is on more than one server before your app hears OK.
group_replication_member_expel_timeout (5 s by default in 8.4) and expel it.group_replication_member_weight, then the lowest server UUID.group_replication_consistency = BEFORE_ON_PRIMARY_FAILOVER, the new primary holds new transactions until it has applied everything it received.For your app: about 10 to 20 seconds without writes, and no committed transaction lost.
Step through it:
Not on Group Replication? Classic source and replicas are failed over by Orchestrator. Running on Kubernetes? See MySQL on Kubernetes with the Percona operators. At fleet scale, see running 1,000 databases.
Run Router next to the app (on each app server, or as a sidecar), not on a single separate box that becomes the new single point of failure. Three members tolerate one failure, five tolerate two.
server_id.mysqlsh -- dba configure-instance root@db1:3306 --clusterAdmin=clusteradmin mysqlsh -- dba configure-instance root@db2:3306 --clusterAdmin=clusteradmin mysqlsh -- dba configure-instance root@db3:3306 --clusterAdmin=clusteradmin
mysqlsh clusteradmin@db1:3306 --js
var c = dba.createCluster('orders')
c.addInstance('clusteradmin@db2:3306', {recoveryMethod: 'clone'})
c.addInstance('clusteradmin@db3:3306', {recoveryMethod: 'clone'})
c.status()
mysqlrouter --bootstrap clusteradmin@db1:3306 --user=mysqlrouter systemctl start mysqlrouter
The app connects to Router on port 6446 for writes and 6447 for reads (classic protocol). c.status() should show "status": "OK", meaning the cluster can tolerate one failure.
member_expel_timeout passes. The two remaining members, a majority, expel db1.group_replication_start_on_boot on, it joins again and catches up from the others (distributed recovery). If it cannot, run c.rejoinInstance('db1:3306'). A member that was expelled while mysqld kept running retries on its own up to group_replication_autorejoin_tries (3) times, then goes to OFFLINE_MODE, the 8.4 default exit action.A planned switchover: c.setPrimaryInstance('db2:3306'). Use it before patching the primary.
| Failure | What happens | What you do |
|---|---|---|
| One member dies | Expelled; if it was primary, a new one is elected. | Nothing at first. c.rejoinInstance('db3:3306') when it is back. |
| Two of three die (no majority) | The last member cannot reach a majority. Writes block. | If the others are truly gone: c.forceQuorumUsingPartitionOf('db3:3306'). Only when you are sure they will not come back on their own. |
| All members stopped (power cut) | Nobody is running Group Replication. | Connect to the member with the most transactions (compare gtid_executed, or use dryRun: true) and run dba.rebootClusterFromCompleteOutage(). |
| A member falls behind | Flow control slows the primary to keep the group together. | Find the cause: disk, a long query, a huge transaction. |
| A table without a primary key | Writes to it fail on the cluster. | Add a primary key before moving to InnoDB Cluster. |
SELECT member_host, member_state, member_role FROM performance_schema.replication_group_members; SELECT member_id, count_transactions_in_queue, count_transactions_remote_in_applier_queue FROM performance_schema.replication_group_member_stats;
Every member should be ONLINE with one PRIMARY. Alert on any member in RECOVERING for long, UNREACHABLE or ERROR, and on growing queues. In MySQL Shell, c.status() gives the same view with advice. Page playbooks: cluster lost its majority, a member in ERROR or OFFLINE.
How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.