By default Matomo is configured to use only one (or two) servers: one database server and one app server. Although this works well, this simple setup has downsides, especially the lack of high availability: if the server goes down, Matomo becomes unavailable.

Multi-servers configuration for Matomo is when you run Matomo on more than one web server, and also when the database is replicated on two servers. This way if one of the web servers goes down, or one of the database server goes down, the Matomo service is not affected.

A multi-servers configuration is also useful to scale horizontally and handle a lot more traffic or large peaks of traffic. (scaling vertically by increasing the current server’s RAM and CPUs can also work great, but running Matomo on one big app server means you don’t have high availability).

Diagram of scalable multi-servers configuration

This diagram below shows a standard setup for a scalable, multi-servers configuration:

The elements in this configuration are:

  • Load balancer
    • forwards all incoming traffic to the Frontend servers
  • Frontend web server(s)
    • running Matomo on a web server and PHP
    • has the crontab every minute running custom-matomo-js:update and tagmanager:regenerate-released-containers commands
    • responsible for Tracking + UI + Reporting API
    • NFS should not be used to store codebase (for performance) but only used to synchronise a few files (see Synchronising the codebase across all web servers)
  • Archiving server(s)
    • running Matomo on PHP via CLI (web server not needed)
    • has the crontab entry setup (hourly core:archive command)
    • responsible for Reports processing + Scheduled tasks
    • NFS should not be used to store codebase (for performance) but only used to synchronise a few files (see faq)
  • Database server
    • running MySQL or MariaDB, storing all Matomo data
    • Possibly 2 servers setup as Master-Slave (source/replica) replication or Master-Master replication
    • RAID and SSD disks are recommended (for performance)
    • NFS should not be used to store data (for performance)

This diagram below shows a more complex setup for a scalable, multi-servers, multi-datacenters, highly available (HA) configuration:

The elements in this configuration are:

  • Load balancer
    • 2 x Highly Available load balancers, for example a F5 load balancer, or floating IP based load balancers
    • forwards all incoming traffic to the Frontend servers
  • N x Frontend web server(s)
    • In this example there are 2 x Frontend servers in one data center, 1 x Frontend in the other.
    • running Matomo on a web server and PHP
    • has the crontab every minute running custom-matomo-js:update and tagmanager:regenerate-released-containers commands
    • responsible for Tracking + UI + Reporting API
    • NFS should not be used to store codebase (for performance) but only used to synchronise a few files (see faq)
  • 1 x Archiving server(s)
    • 1 x Archiving server is generally sufficient.
    • If the server has an issue, it can be easily re-created and deployed. The impact to Matomo service is reasonably low: new reports won’t be processed or email reports sent while the Archiving server is unavailable.
    • running Matomo on PHP via CLI (web server not needed)
    • has the crontab entry setup (hourly core:archive command)
    • responsible for Reports processing + Scheduled tasks
    • NFS should not be used to store codebase (for performance) but only used to synchronise a few files (see faq)
  • 2 x Database server
    • 1 x Database server in each datacenter
    • running MySQL or MariaDB, storing all Matomo data
    • setup as Master-Slave replication (source/replica) or Master-Master replication (for HA)
    • low latency is needed between the two data centers to ensure efficient replication
    • RAID and SSD disks are recommended (for performance)
    • NFS should not be used to store data (for performance)

Deploying the same codebase on all servers

When running Matomo on multiple servers it is required that the same codebase is deployed on
all servers. See: How to deploy the same codebase on all servers?

Synchronising config files and tracker JS files

When running Matomo on multiple servers it is required to synchronise the config and tracker js files. See: How to synchronise config and tracker JS files?

Running Matomo in Docker

One way to make a scalable, multi-server configuration is to use Docker. As a starting point you may refer to the above article and also the official Docker project for Matomo Analytics.