When your application does not have support for loadbalancing to multiple master DB nodes it's best to have a loadbalancer infront.
HAProxy is a free alternative but so far I've only tried MaxScale.
Observe that MaxScale uses a special commercial open source license that requires you pay for using it with more than 3 DB nodes.
You must download it through the MariaDB portal, there is no package repository yet.
The configuration can be broken down into these steps.
[node1] type=server address=node1 port=3306 protocol=MySQLBackend serv_weight=3 [node1] type=server address=node1 port=3306 protocol=MySQLBackend serv_weight=2 [node1] type=server address=node1 port=3306 protocol=MySQLBackend serv_weight=2
Some notes on this:
addressmust be an IP or DNS name that can be resolved
serv_weightdecides how many connections are given to the node
The service decides in which way you will loadbalance connections, for example you can split reads from writes or you can try to balance all reads and writes across all nodes.
Here's an example that balances all reads and writes across all nodes based on their
[Galera Service] type=service router=readconnroute router_options=synced servers=node1,node2,node3 user=maxscale passwd=secret. max_slave_connections=100% weightby=serv_weight
routercan be set to many different things, see the docs
router_optionsdecides if you want to balance connections only to synced nodes
passwdgive maxscale administrative access to the server and requires special grants that you can read about later
Work in progress.