Galera Cluster

Galera Replication

  • Galera replication happens at transaction commit time, by broadcasting transaction write set to the cluster for applying
  • Client connects directly to the DBMS and experiences close to native DBMS behavior
  • wsrep API (write set replication API), defines the interface between Galera replication and the DBMS



Synchronous vs. Asynchronous Replication

The basic difference between synchronous and asynchronous replication is that “synchronous” guarantees that if changes happened on one node of the cluster, they happened on other nodes “synchronously”. “Asynchronous” gives no guarantees about the delay between applying changes on “master” node and the propagation of changes to “slave” nodes. The delay can be short or long – it is a matter of luck. This also implies that if master node crashes, some of the latest changes may be lost.


Theoretically synchronous replication has a number of advantages over asynchronous:


  • it is always highly available (there is no data loss when one of the nodes crashes, and data replicas are always consistent)
  • transactions can be executed on all nodes in parallel.
  • it can guarantee causality across the whole cluster (SELECT S issued after transaction T will always see the effects of transaction even if it is executed on another node)


However in practice synchronous database replication was traditionally implemented via the so-called “2-phase commit” or distributed locking which proved to be very slow. Low performance and complexity of implementation of synchronous replication led to a situation where asynchronous replication remains the dominant means for database performance scalability and availability. Widely adopted open-source databases such as MySQL or PostgreSQL offer only asynchronous replication solution.


Certification Based Replication Method

An alternative approach to synchronous database replication using Group Communication and transaction ordering techniques was suggested by a number of researchers (e.g. Database State Machine Approach and Don’t Be Lazy, Be Consistent) and prototype implementations have shown a lot of promise. We combined our experience in synchronous database replication and the latest research in the field to create Galera Replication Toolkit.

Galera replication is a highly transparent and scalable synchronous replication solution for application clustering to achieve high availability and improved performance. Galera-based clusters are:


  • Highly available
  • Highly transparent
  • Highly scalable (near linear scalability may be reached depending on the application)


Generic Replication Library

Galera replication functionality is implemented as shared library and can be linked with any transaction processing system, which implements the wsrep API hooks. Galera replication library is a protocol stack providing functionality for preparing, replicating and applying of transaction write sets. It consists of:


  • wsrep API specifies the interface – responsibilities for DBMS and replication provider
  • wsrep hooks is the wsrep integration in the DBMS engine.
  • Galera provider implements the wsrep API for Galera library
  • certification layer takes care of preparing write sets and performing certification
  • replication manages replication protocol and provides total ordering capabilities
  • GCS framework provides plugin architecture for group communication systems
  • many gcs implementations can be adapted, we have experimented with spread and our in-house implementations: vsbes and gemini

Use cases

Use case

Read Master

Traditional MySQL master-slave topology, but with Galera all “slave” nodes are capable masters at all times, it is just the application who treats them as slaves. Galera replication can guarantee 0 slave lag for such installations and due to parallel slave applying, much better throughput for the cluster.

Use case

Write scalability

Distributing writes across the cluster will harness the CPU power in slave nodes for better use to process client write transactions. Due to the row based replication method, only changes made during a client transaction will be replicated and applying such a transaction in slave applier is much faster than the processing of the original transaction. Therefore the cluster can distribute the heavy client transaction processing across many master nodes and this yields in better write transaction throughput overall.

Use case

WAN Clustering

Synchronous replication works fine over the WAN network. There will be a delay, which is proportional to the network round trip time (RTT), but it only affects the commit operation.

Use case

Disaster Recovery

Disaster recovery is a sub-class of WAN replication. Here one data center is passive and only receives replication events, but does not process any client transactions. Such a remote data center will be up to date at all times and no data loss can happen. During recovery, the spare site is just nominated as primary and application can continue as normal with a minimal fail over delay.

Use case

Latency Eraser

With WAN replication topology, cluster nodes can be located close to cilents.Therefore all read & write operations will be super fast with the local node connection. The RTT related delay will be experienced only at commit time, and even then it can be generally accepted by end user, usually the kill-joy for end user experiences is the slow browsing response time, and read operations are as fast as they possibly can be.