Website/webserver fault tolerance - the best practices

1.8k views Asked by At

For example, I have two servers in the same network, with identical code/software. If the primary server goes down, I want the second one to become primary.

I heard about the following approaches:

What are the pros and cons of the above approaches? And what are the best practices to achieve this?

2

There are 2 answers

3
Louis Kriek On BEST ANSWER

I'm not too familiar with CARP but I can try to help with the remaining two options:

Round-Robin DNS gives you load balancing but if a server fails it will still receive requests (which will fail too)
i.e : the DNS www.example.com points to both x.x.x.1 and x.x.x.2
if x.x.x.2 dies the DNS will still be resolved to x.x.x.2 and clients will still try to request from it, so this brings your fail rate to half your requests during the downtime (not good)
Even if you change the DNS to point to only x.x.x.1 during the downtime; DNS propagation will take long and you will still loose requests.

In my honest opinion placing a load balancer (proxy server) in front of your stack is the only way to go
I'm really fond of HAProxy but its by no means the only solution (find what works for you)

Proxy-Servers gives you a lot more control over your application stack in the form of High Availability (HA)
you can load balance between 2 to N backend servers and loose any number of them and still be running.
you can schedule downtime anytime of the day to do maintenance or deployments and not influence your clients.
Built in health checks poll the backend servers and take them out of the load as needed and place them back when they've recovered.
The cons to HA Load Balancing is usually the number of rules that have to be setup in order to keep sessions correct or routing of special cases. yes it can get complex but there is A LOT of support in the community and its easily learn-able. another con to HA Load Balancing is that the proxy server itself become a single point of failure but this can be overcome easily with heartbeatd and a second proxy server.

Hope this answers some of your questions

0
JasdeepSingh On

A good way for making your apps fault tolerant would be using nginx as your load balancer. You can make a config like

upstream some_name {
  server server_ip; 
  server server_ip2; 
};
server { 
    listen 80; 
    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For 
            $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://some_name 
     }
}

plus this nginx upstream object takes further flags like max_fails=10 fail_timeout=20s and is smart enough to know if one server goes down, it switches to the next server that's online and so much more than that. Please check this official nginx website for more information about it.