Galera Cluster

On this page 6

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.

PhaseWhere it runsWhat happens
Local executionOrigin node onlyStatements run with local row locks
ReplicationAll nodes via group communicationWriteset receives a global sequence number
CertificationEvery node independentlyKey conflicts with concurrent writesets are checked
Commit or rollbackOrigin nodeClient receives success or a deadlock error
ApplyRemaining nodesApplier threads write the certified changes
Lifecycle of a write transaction in Galera Cluster

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.

MethodWhen it is usedCost
Incremental state transfer (IST)Missing writesets still in a donor’s gcacheFast, only the gap is sent
State snapshot transfer (SST)Gap too large or a brand-new nodeFull copy of the dataset
SST with mariabackup or xtrabackupProduction clustersDonor stays mostly available
SST with rsync or mysqldumpSmall or test datasetsDonor blocked during transfer
State transfer methods in Galera Cluster

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.

ApproachData loss on primary failureWritable nodesWrite latency
Asynchronous replicationPossibleOne primaryLocal commit only
Semi-synchronous replicationRare, depends on settingsOne primaryOne replica acknowledgment
MySQL Group ReplicationNone within the groupSingle or multi-primaryMajority round trip
Galera ClusterNone for committed dataAll nodesTotal-order round trip
Galera Cluster and alternative replication approaches

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.

SymptomLikely causeFix
Frequent deadlock errorsConcurrent writes to the same rowsRoute writes to one node, add retries
Cluster-wide stallsFlow control from a slow nodeMatch hardware, raise applier threads
Full SST after restartgcache too smallIncrease gcache size
Non-primary stateLost quorum after partitionRestore majority or bootstrap carefully
Common Galera problems and fixes

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.