Deploy MariaDB HA

MariaDB Galera: 3-node multi-master cluster with auto-failover.

Deploy MariaDB HA

Just deployed

/var/lib/mysql

Just deployed

/var/lib/mysql

Just deployed

/var/lib/mysql

Deploy and Host MariaDB HA on Railway

A 3-node MariaDB Galera cluster with multi-master replication and automatic failover. Built for production workloads that need a MySQL-compatible relational database that survives node failures.

About Hosting

MariaDB HA deploys a 3-node Galera cluster on Railway's private network. All three nodes are active masters — any node accepts reads and writes, and changes are replicated synchronously to all other nodes. Galera uses wsrep (write-set replication) for certification-based replication, ensuring data consistency across the cluster. State Snapshot Transfer (SST) via mariabackup handles full data sync when a new or recovered node joins. Each node has its own persistent volume. The cluster requires a quorum (majority) for operation, so 2 of 3 nodes must be available. The bootstrap node is determined automatically — if no peers are reachable, node 1 bootstraps a new cluster; otherwise it joins the existing one. MariaDB 11.8 LTS includes the Galera library natively, no separate coordination service needed.

Common Use Cases

  • Web application databases — WordPress, Drupal, Laravel with high availability
  • E-commerce platforms — product catalogs, orders, and inventory with zero downtime
  • SaaS backends — multi-tenant databases with automatic failover
  • API backends — relational data storage for REST/GraphQL APIs
  • Session storage — shared sessions across multiple app instances
  • Reporting and analytics — read queries distributed across replicas

Dependencies for

  • MariaDB 11.8 — official mariadb:11.8-noble image (106 MB)
  • Galera wsrep provider — included in the MariaDB image (libgalera_smm.so)
  • mariabackup — included for State Snapshot Transfer (SST)
  • Railway volumes — one persistent volume per node at /var/lib/mysql (3 volumes total)
  • Railway private networking — IPv6 inter-service communication

Implementation Details

Each node runs MariaDB with Galera replication enabled. The entrypoint renders a galera.cnf config file with the cluster address, SST auth, and required settings. Node 1 bootstraps a new cluster when no peers are reachable; otherwise all nodes join the existing cluster. The bind-address is set to :: for IPv6 compatibility with Railway's private network.

Default credentials: Root password is auto-generated via ${{secret(32)}} on mariadb-1 and shared with all nodes. Set MARIADB_ROOT_PASSWORD before deploy to control it.

Creating a database and user:

Set MARIADB_DATABASE, MARIADB_USER, and MARIADB_PASSWORD on all nodes to auto-create a database and user on first boot.

Connecting to the cluster:

Connect to any node — all accept reads and writes:

mysql -h mariadb-1.railway.internal -P 3306 -u root -p

For external access, add a TCP proxy on port 3306 to any node.

Connecting via code (Python example):

import mysql.connector

conn = mysql.connector.connect(
    host="mariadb-1.railway.internal",
    port=3306,
    user="root",
    password="",
    database="mydb"
)
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name VARCHAR(100))")
cursor.execute("INSERT INTO users VALUES (1, 'Alice')")
conn.commit()
cursor.execute("SELECT * FROM users")
print(cursor.fetchall())
conn.close()

Verifying cluster status:

SHOW STATUS LIKE 'wsrep_cluster_size';      -- Should show 3
SHOW STATUS LIKE 'wsrep_cluster_status';    -- Should show Primary
SHOW STATUS LIKE 'wsrep_local_state_comment'; -- Should show Synced

Testing failover:

  1. Connect to mariadb-1 and insert data
  2. Stop mariadb-1
  3. Connect to mariadb-2 — data should be available (written on mariadb-1, replicated)
  4. Insert new data on mariadb-2
  5. Restart mariadb-1 — it rejoins and syncs automatically

Ports:

PortPurposeExposure
3306MySQL protocolPrivate + TCP proxy for external
4567Galera replication (wsrep)Private (cluster only)
4568IST (Incremental State Transfer)Private (cluster only)
4444SST (State Snapshot Transfer)Private (cluster only)

Volume: One volume per node at /var/lib/mysql. Galera data and grastate.dat persist here.

Health check: MariaDB responds to mysqladmin ping on port 3306.

Comparison with Alternatives

FeatureMariaDB Galera (this template)Single MariaDBMySQL HA (Railway managed)PostgreSQL HA
Multi-master✅ All nodes accept writes❌❌ (primary only)❌ (primary only)
Automatic failover✅ Galera handles it❌✅ Sentinel-based✅ Patroni-based
Setup complexity⚠️ 3 services✅ 1 service✅ 1-click conversion⚠️ Patroni + etcd
MySQL compatibility✅ Full✅ Full✅ Full❌ Different protocol
Synchronous replication✅ Certification-based❌❌ Async✅ Sync/Async
Cost (self-hosted)⚠️ 3 services✅ 1 service❌ Managed only⚠️ 3+ services
Data consistency✅ Strong✅ Strong⚠️ Eventual✅ Strong
Self-hosted✅✅❌✅

Security Considerations

  • Root password: Auto-generated via ${{secret(32)}} on mariadb-1. Shared across all nodes. Set MARIADB_ROOT_PASSWORD before deploy to control it.
  • SST authentication: Uses root credentials for state transfer. Consider creating a dedicated SST user in production.
  • Network access: Port 3306 accessible via TCP proxy for external clients. Galera ports (4567, 4568, 4444) are private only.
  • User management: Set MARIADB_USER and MARIADB_PASSWORD to create an application user with limited privileges.
  • Volume encryption: Railway volumes are encrypted at rest.
  • No public Galera ports: Replication ports are private only.

Why Deploy MariaDB HA on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying MariaDB HA on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Three nodes with multi-master replication, automatic failover, and synchronous consistency — no separate coordination service, no manual Galera configuration. Set the password and deploy.


Template Content

More templates in this category

View Template
RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set
S3-compatible object store, keys and public URL preset, volume kept

SuperSlowSloth
0
View Template
TimescaleDB
Time-series analytics on PostgreSQL: fast, familiar, scalable.

Rakit
2
View Template
Neo4j 2026.10 Community
Neo4j graph database with APOC, Browser, Bolt TCP proxy and a volume

My Projects
0