How to host a WordPress site on multiple servers due to geographical siteload issues?

Alex asked:

WordPress website is currently hosted in the US, this is where 40% of our target audience is. The rest of visitors are coming form Middle east, Australia, Russia, China, Singapore, UK, Switzerland, Kazakstan… all over the map.

With all caching in place (not CDN) it still barely loads in Asia / Oceania and has speed issues in Europe.

Can I simply setup multiple servers and create multiple A records that point to different servers in different regions and assume that a visitor from Australia will be served form australian server?

Any tips?

My answer:


The problems with geographically distributing WordPress, as you’ll see, all revolve around the MySQL database.

There are basically two ways to architect this:

Read replicas

In this architecture, you run your LAMP frontend with WordPress in several geographic locations, each of which has a read-only replica (slave) of the master MySQL database. You will need to use something like MySQL Proxy to direct write operations back to the master, as WordPress doesn’t natively support using a different database connection for reads versus writes.

The big problem with this setup is that if your master goes down, you can’t make changes (e.g. no new posts or comments). So the master should probably be clustered or otherwise protected (e.g. using Amazon RDS Multi-AZ). Database writes are also delayed slightly due to network latency between the LAMP frontend and the remote MySQL master.

Multi-master

In this architecture, you run your LAMP frontend with WordPress in several geographic locations, each of which has a multi-master replicated database, using something like MariaDB Galera or an equivalent MySQL solution (if you can find one). You need to have at least three masters if you go this route.

As there’s no single point of failure, it really doesn’t matter if one master goes down (so long as they don’t ALL go down at the same time; that situation requires manual intervention to recover).

The problem with this is that writes take much longer, as they have to be replicated to all of the multiple masters. So people may notice a few seconds’ delay when doing anything that writes to the DB, such as commenting or writing a new post. In practice, this delay isn’t that significant, as users already expect delays when they submit information in these contexts.


If you have three or more geographic locations you’re going to deploy to, I’d go ahead and spend the effort to go multi-master. If you only have two locations, you can get by with a read replica and proxy for now.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.