Q: How do you configure MariaDB MaxScale for automated master failover and transparent read/write splitting?
MariaDB interview questions on MaxScale: configure mariadbmon auto_failover and auto_rejoin, a readwritesplit router, listener, transaction_replay, and causal_reads.
Want to master this scenario in a live sandbox? KodeKloud's PostgreSQL Database Administration & High Availability Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: In mariadb interview questions about MaxScale, the interviewer is checking that I can separate three jobs: the monitor decides who is primary, the router decides where each statement goes, and the listener is the single endpoint applications connect to. I want applications to keep one connection string while a primary crash turns into a short blip instead of a paging incident. I walk through the monitor, the router, the failure behaviour, and how I verify it with maxctrl before trusting it.
Create the service accounts MaxScale needs
MaxScale needs one account for the monitor and one for the router to authenticate clients. The monitor account needs replication and administrative privileges so it can promote a replica and repoint the others. The service account needs read access to the grant tables to authenticate users. I create both on the primary so they replicate everywhere, and I check the privilege list for mariadbmon in the MaxScale documentation for my version.
CREATE USER 'maxmon'@'10.0.1.%' IDENTIFIED BY 'change-me-mon';
GRANT SUPER, RELOAD, PROCESS, SHOW DATABASES, EVENT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'maxmon'@'10.0.1.%';
CREATE USER 'maxsvc'@'10.0.1.%' IDENTIFIED BY 'change-me-svc';
GRANT SHOW DATABASES ON *.* TO 'maxsvc'@'10.0.1.%';
GRANT SELECT ON mysql.user TO 'maxsvc'@'10.0.1.%';
GRANT SELECT ON mysql.db TO 'maxsvc'@'10.0.1.%';
GRANT SELECT ON mysql.tables_priv TO 'maxsvc'@'10.0.1.%';
GRANT SELECT ON mysql.roles_mapping TO 'maxsvc'@'10.0.1.%';
Define servers and the mariadbmon monitor with automatic failover
The mariadbmon module watches replication topology. With auto_failover on, it promotes the most up to date replica when the primary has been unreachable for failcount monitor intervals. With auto_rejoin on, a recovered old primary is reconfigured as a replica of the new one. I keep failcount high enough to ride out a brief network hiccup, and I set enforce_read_only_slaves so replicas cannot take stray writes.
# /etc/maxscale.cnf
[server1]
type=server
address=10.0.1.11
port=3306
protocol=MariaDBBackend
[server2]
type=server
address=10.0.1.12
port=3306
protocol=MariaDBBackend
[server3]
type=server
address=10.0.1.13
port=3306
protocol=MariaDBBackend
[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=maxmon
password=change-me-mon
replication_user=repl
replication_password=change-me-repl
monitor_interval=2000ms
auto_failover=true
auto_rejoin=true
failcount=5
enforce_read_only_slaves=true
Add the readwritesplit router and the listener
The readwritesplit router sends writes and statements inside write transactions to the primary and spreads plain SELECTs across replicas. The listener exposes it on one port. With transaction_replay, MaxScale replays an open transaction on the new primary after a failover when it can prove the replayed results match, so many clients never see an error. I also set master_reconnection so sessions survive a primary change.
[Splitter-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxsvc
password=change-me-svc
transaction_replay=true
transaction_replay_timeout=30s
master_reconnection=true
master_failure_mode=fail_on_write
[Splitter-Listener]
type=listener
service=Splitter-Service
protocol=MariaDBClient
port=4006
Handle read-your-writes with causal_reads
Replica reads can return stale rows right after a write. Setting causal_reads makes the router wait for the replica to reach the GTID of the client's last write before answering, or fall back to the primary on timeout. It costs latency, so I enable it per service only where the application really reads back what it just wrote, such as order confirmation pages.
[Splitter-Service]
causal_reads=local
causal_reads_timeout=10s
# Apply and verify the config loads
sudo systemctl restart maxscale
maxctrl show service Splitter-Service | grep -i causal
Verify the topology and rehearse a failover
I never trust a failover config I have not exercised. maxctrl list servers shows which node is Master and which are Slave, and I stop mariadb on the primary in a staging window while a loop writes through port 4006. I expect a new Master within roughly failcount times the monitor interval, then confirm the old primary rejoins as a replica.
maxctrl list servers
# Server Address State
# server1 10.0.1.11 Master, Running
# server2 10.0.1.12 Slave, Running
# server3 10.0.1.13 Slave, Running
sudo systemctl stop mariadb # on server1, staging only
sleep 15; maxctrl list servers
# server1 10.0.1.11 Down
# server2 10.0.1.12 Master, Running
# Planned move instead of a crash
maxctrl call command mariadbmon switchover MariaDB-Monitor server3 server2
- MaxScale gives applications one listener port while a monitor tracks which backend is primary.
- mariadbmon with auto_failover promotes the best replica after failcount missed checks, and auto_rejoin turns the recovered node into a replica.
- readwritesplit sends writes to the primary and reads to replicas, with transaction_replay and causal_reads reducing visible errors and stale reads.
- I validate by stopping the primary in staging and confirming topology with maxctrl list servers.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Running a single MaxScale instance with no HA The proxy becomes the new single point of failure. Run two instances with a virtual IP or load balancer in front, and let only one act on failover.
- Enabling auto_failover with a failcount of 1 A single missed health check during a network blip triggers a promotion and can cause a flapping topology.
- Turning on causal_reads for every query Each read may wait on replica catch-up, which adds latency and shifts load back to the primary under lag.
- Assuming transaction_replay always works Transactions with non-deterministic functions or large results cannot be replayed safely, so applications still need retry logic.