DNS Round Robin

Hi all,
I was considering to use DNS Round Robin in order to load balance requests between two geographically different servers. DB is already shared using a Master-Master replication, what about cookie sessions when directing traffic to two different servers? Anyone has experience with this? Thanks.

  1. You can set PHP to use a different storage type for sessions. You just need to use a DB, or memcached, or Redis, etc.

  2. Highly recommend NOT just doing naive round-robin with servers in different locations. Why not just use Amazon’s Route 53 and geo-routing? http://aws.amazon.com/about-aws/whats-new/2014/07/31/amazon-route-53-announces-domain-name-registration-geo-routing-and-lower-pricing/. PowerDNS offers geo-based routing as well.

Thanks, why not DNS round robin?

Well there’s nothing really wrong with it. But you may as well take advantage of the fact that you have geographically different servers by using the one closest to someone to serve the request.

The two servers are geographically speaking quite near and we use our own DNS servers, the backend MySQL DB is synched between the two servers so sessions can be kept there. The idea is that one server can work as failover for the other, if one goes down the other should be able to offer the same services. Can we deploy to both servers with capistrano during the deployment process? Thanks.

My blind suggestion without knowing your setup: use a provider for DNS. They’re probably better and easier and Amazon or Google’s DNS services are dirt cheap.

Re: capistrano: Of course. Just add multiple server declaration’s in a stage file:

server 'app1.example.com', user: 'deploy', roles: %w{web app}
server 'app2.example.com', user: 'deploy', roles: %w{web app}

And you have options to control the process like:

on roles(:web), in: :sequence, wait: 5 do

See https://github.com/capistrano/sshkit#parallel

1 Like

Perfect, thanks @swalkinshaw!

What about haproxy? someone has experience with this?

For now we have two geographically distant servers:

Web User -> Server 1 -> Varnish -> Apache2 -> MySQL

Web User -> Server 2 -> Varnish -> Apache2 -> MySQL

MySQL is replicated Master-Master, we’re going to setup GluserFS for WP uploads synch, seems to work.
As far as we don’t have a load balancer in front of all, but just plain DNS, we we’re thinking about:

Web User -> Server 1 -> Haproxy -> Varnish -> Apache2 -> MySQL

Web User -> Server 2 -> Haproxy -> Varnish -> Apache2 -> MySQL

this way the two Haproxy instances could eventually redirect traffic mutually from one server to the other in case a critical service in the chain is down. The two servers are in different DCs. Thanks,

I.

Usually you’d just have 1 haproxy instance doing the load balancing. But if you wanted that setup, might as well just skip haproxy since Varnish can do load balancing as well: https://www.varnish-cache.org/trac/wiki/LoadBalancing

Hi Swalkinshaw, thanks for reply.
With only one haproxy, let’s say on Server 1, if this goes down all goes down, the whole setup should be mutual redundant. If Varnish should do this job I have to check if Varnish can make healt checks on MySQL and Apache2.