MariaDB/MySQL Auto-Сlustering with Load Balancing and Replication for High Availability and Performance

| October 20, 2020

Database clusterization is an obligatory requirement for highly loaded production applications to ensure data availability and high performance. However, the configuration of a reliable cluster is not a trivial task even for experienced developers and system administrators. For solving this problem, Jelastic introduced out-of-the-box clustering for MariaDB/MySQL to make applications highly available by default.mysql group replication multi primary

The implemented solution provides a set of benefits:

  • high availability with pre-configured replication options - Master-Slave, Master-Master, Galera
  • scalability and autodiscovery – new nodes, added during horizontal scaling, are connected to the cluster with all required adjustments being applied automatically
  • efficient load balancing – each cluster is supplemented with two ProxySQL nodes for load balancing with automatic splitting of read/write requests
  • automated failover – the database nodes that are temporarily unavailable or have high latency are automatically excluded from the cluster and re-added once the connection is restored

All these benefits can be achieved just in a few clicks within a topology wizard. Explore the steps below to activate auto-clustering for your MariaDB and MySQL databases in Jelastic PaaS.

Enable Automatic Clustering for Databases

Click on NEW ENVIRONMENT at the dashboard and choose MariaDB or MySQL database.

out of box mysql cluster

Activate the Auto-Clustering button. As a result, a dropdown with different replication schemes will appear:

  • MariaDB - Master-Slave, Master-Master, and Galera
  • MySQL - Master-Slave and Master-Master

Auto-Clustering Options

Choose the replication type you prefer, add the necessary number of nodes.

Highly Available ProxySQL Load Balancer

Each MariaDB/MySQL auto-clustering solution has two ProxySQL nodes  enabled by default in front of the database cluster. If required you can exclude them from the cluster topology before installation with the respective switch. Keep in mind that you won’t be able to do that afterward.

auto-clustering proxysql

Database Cluster Access Credentials

During cluster creation, Jelastic automatically generates database access credentials, but you may override them with your own ones in three simple steps:

1. Click on the Variables button.

auto-clustering variables

2. Then press Add to provide custom user’s database credentials via two variables DB_USER and DB_PASS as follows:

  1. database credentials

3. Press Apply and custom credentials will be mailed to you upon cluster successful installation as for access to the PHP MyAdmin at Master Node and database cluster Entry Point.

Cluster Horizontal Scaling

If you decide to scale the master-slave/master-master topologies with an extra database node, it will be created via cloning an existing slave node. Once the cloning procedure is completed the database on the new cluster member catches up data via binlog replay. Such an algorithm guarantees the binlog will never expire and horizontal scaling takes a short period of time.

Cluster Layers Isolation

Depending on whether you are going to use an external application or not, you may decide what layers you will expose outside - all or the entry point proxy layer only. Turn the SLB access switch into the required position for each layer and click Create.

  1. auto-clustering environment

That’s all! No configurations required, the cluster is ready to work with.

  1. mariadb auto-cluster replication topology
  1. Database Cluster Access Information

After successful installation, you’ll receive a number of emails with the cluster information:

    • PHP MyAdmin at Master Node  web administration interface with credentials to access the database server for interactive management.mysql mariadb admin panel
    • Entry Point for Connections to MySQL Cluster - hostname and credentials for connecting an application to the database cluster.These nodes form a proxy layer referred to as the entry point for the database cluster with hostname as follows: proxy.${envName}.${platformDomain}.


Note: In case you are going to create and use the custom user accounts after cluster installation, you should add them to the mysql_users table on each ProxySQL node, otherwise you won’t be able to establish connection to the database via the proxy layer. To do this issue commands below:

$ MYSQL_PWD=admin mysql -h -P6032 -uadmin -e "INSERT INTO mysql_users (username,password,default_hostgroup) VALUES ('<username>', '<password>', 2);"


Substitute <username> and <password> with credentials of a newly created database account.

  • Cluster Orchestrator Panel - credentials to access the Orchestrator panel, intended for convenient cluster management. Use the received credentials to access admin panel of cluster Orchestrator installed on ProxySQL node, that provides a possibility to review the cluster topology information: slick visualization of topologies, replication problems if there are any, read/write distribution, state of health check-ups and autodiscovery of newly added DB nodes, etc.

mysql auto clustering orchestrator

What Replication Type to Choose?

Let’s consider the details about each replication scheme available for databases within Jelastic in order to understand which one is the most suitable for the specific needs and use cases.

Master-Slave MariaDB/MySQL Replication

Master-slave replication is the most common used topology, that provides a good consistency (i.e. exactly one node to modify data), but no automatic failover upon master failure. A write latency in asynchronous replication is low because the write is recorded locally by the master server before writing to the slave servers. It allows to scale-out the reads, providing the highest performance,  since adding more replicas does not affect replication latency. Slaves can be read without impact on the master, providing such obvious advantages as:

  • High performance for read requests
  • Database backup can be done with no impact on master instance
  • Analytical requests can load the slave instance only without affecting the master

Master-Slave MariaDB and MySQL Replication

Master-Master MariaDB/MySQL Replication

Master-master asynchronous replication operates with two master nodes simultaneously, Compared to the default master-slave solution, it benefits on the balancing of writing load and simpler recovery upon one master node failure.db auto clustering

In contrast to the default settings, in Jelastic master-master cluster scaling leads to slaves addition to the cluster. Upon creation, the slave instances are equally distributed between master nodes that allow smoothly distribute the replication workload and increase the reads capacity of the cluster.

MariaDB Galera

Galera cluster is a type of multi-master synchronous replication which is performed at a transaction commit time, by broadcasting transaction write set to all cluster nodes for applying and makes sure the write that was sent to all nodes in the cluster before this write will be actually committed.db auto clustering

A user application can send reads and writes to any node in the cluster, that provides an ability to scale-out read and write transactions. Adding nodes to a cluster is fully automated. Excluding nodes from the cluster is just a matter of removing the unneeded or failed ones. There is no need anymore to implement the bulky logic for separation of reads and writes, the scaling potential can be immediately implemented with no need to change the application logic. Galera offers one of the best protection against data loss and inconsistent databases since there is no delay in replicating data. If one of the cluster nodes fails the user application won't see it and will continue to serve users using the other nodes that may also be located in other data centers.

In the upcoming articles, we’ll dive deeper into the specifics of each database auto-clustering implementation. So stay tuned and do not hesitate to give a try of the database clusterization functionality at one of the Jelastic service providers.

Related Articles

Master-Slave and Master-Master Replication with MariaDB/MySQL Auto-Сlustering

MariaDB Galera Cluster Replication

PostgreSQL Auto-Clustering with Asynchronous Master-Slave Replication

MongoDB Replica Set Auto-Сlustering for High Availability and Performance