Galera Cluster is a synchronous multi-primary replication system for MySQL and MariaDB in which every node accepts reads and writes and every committed transaction is certified and applied on all nodes in the same global order. In replication for databases, it is the best-known example of virtually synchronous, certification-based replication, built on the open-source wsrep API and the Galera replication library.
It is distributed as a patch set and plugin in MariaDB Galera Cluster, Percona XtraDB Cluster and Galera Cluster for MySQL. Its main promise is no data loss on node failure and no replication lag for committed data, in exchange for write latency bounded by the network and stricter workload requirements.
How Galera certification-based replication works
A transaction executes optimistically on the local node with normal InnoDB row locks. At commit time, the node packages the changed rows and their primary keys into a writeset and broadcasts it through a group communication layer that delivers all writesets to all nodes in one total order, each tagged with a global transaction ID.
Every node then runs the same deterministic certification test: if a writeset touches keys modified by a concurrent writeset that was ordered earlier, it fails. Because each node reaches the same verdict independently, no extra voting round is needed. A failed transaction is rolled back on its origin node with a deadlock error, while a certified one commits locally and is applied asynchronously by applier threads on the other nodes.
The steps and their cost are summarized in the following table.
| Phase | Where it runs | What happens |
|---|---|---|
| Local execution | Origin node only | Statements run with local row locks |
| Replication | All nodes via group communication | Writeset receives a global sequence number |
| Certification | Every node independently | Key conflicts with concurrent writesets are checked |
| Commit or rollback | Origin node | Client receives success or a deadlock error |
| Apply | Remaining nodes | Applier threads write the certified changes |
Strictly speaking, replication is synchronous for ordering and certification but asynchronous for applying, which is why the project calls it virtually synchronous. A reader on another node can briefly miss a change unless wsrep_sync_wait forces the node to catch up before answering.
Membership, quorum and node provisioning
Galera tracks cluster membership as a primary component. After a network partition, only the group holding a majority of weighted votes stays primary and keeps accepting writes, while minority nodes refuse queries. This quorum rule prevents split-brain, and it is the reason clusters are built with an odd number of nodes, typically three, or with the lightweight Galera Arbitrator (garbd) as a tiebreaker.
New or returning nodes obtain data in one of two ways, compared below.
| Method | When it is used | Cost |
|---|---|---|
| Incremental state transfer (IST) | Missing writesets still in a donor’s gcache | Fast, only the gap is sent |
| State snapshot transfer (SST) | Gap too large or a brand-new node | Full copy of the dataset |
| SST with mariabackup or xtrabackup | Production clusters | Donor stays mostly available |
| SST with rsync or mysqldump | Small or test datasets | Donor blocked during transfer |
Sizing the gcache ring buffer to cover normal maintenance windows is one of the most effective tuning steps, because it turns an expensive SST into a quick IST after a routine restart.
Galera Cluster compared with other MySQL replication options
Galera competes mainly with asynchronous and semi-synchronous replication and with MySQL Group Replication, which uses a similar certification idea on top of a Paxos-based protocol. The comparison below highlights the practical differences.
| Approach | Data loss on primary failure | Writable nodes | Write latency |
|---|---|---|---|
| Asynchronous replication | Possible | One primary | Local commit only |
| Semi-synchronous replication | Rare, depends on settings | One primary | One replica acknowledgment |
| MySQL Group Replication | None within the group | Single or multi-primary | Majority round trip |
| Galera Cluster | None for committed data | All nodes | Total-order round trip |
Unlike primary-replica setups, Galera needs no failover promotion: a load balancer such as ProxySQL or HAProxy simply stops routing to a failed node. Unlike geo-replication designs, it is poorly suited to distant data centers, because every commit waits for a cluster-wide round trip.
Requirements and limitations
Galera imposes hard workload rules that teams should verify before migration:
- Only the InnoDB storage engine is replicated reliably; MyISAM support is experimental.
- Every table needs a primary key, otherwise row identification and parallel applying break down.
- Large transactions inflate writesets and memory use; streaming replication in Galera 4 helps but adds overhead.
- DDL statements use total order isolation by default, which briefly blocks writes across the whole cluster.
- Explicit table locks and some locking functions behave differently or are unsupported.
The most common operational surprise is flow control: when one node falls behind, it pauses replication for the whole cluster, so the slowest node sets cluster throughput. Multi-primary writes to the same hot rows cause frequent certification failures, so many deployments send all writes to one node and use the others for reads and failover.
| Symptom | Likely cause | Fix |
|---|---|---|
| Frequent deadlock errors | Concurrent writes to the same rows | Route writes to one node, add retries |
| Cluster-wide stalls | Flow control from a slow node | Match hardware, raise applier threads |
| Full SST after restart | gcache too small | Increase gcache size |
| Non-primary state | Lost quorum after partition | Restore majority or bootstrap carefully |
Understanding it simply
Think of three accountants keeping identical ledgers. Before any of them writes an entry, they announce it to the group, everyone agrees on the order of entries, and each checks that it does not clash with another entry made at the same moment. If it clashes, the later one is canceled and must be tried again.
Because every accountant follows the same rules, all ledgers always agree. If one accountant leaves, the other two carry on with nothing lost. The price is that each entry takes a little longer, since the group must hear about it first.
Applied in practice
An online ticketing company runs its booking database as a three-node MariaDB Galera Cluster in one region, with nodes in three separate availability zones about one millisecond apart. ProxySQL sends all writes to a single designated node and spreads reads across all three, which avoids certification conflicts on popular events.
During a large concert sale, the hardware under the write node fails. ProxySQL detects the failure within seconds and promotes another node as the write target; because every committed booking already existed on the surviving nodes, no orders are lost and no manual promotion is needed. The failed node later rejoins through incremental state transfer from a 2 GB gcache, catching up in under a minute instead of copying the full 400 GB dataset.