# difference between failover,replication and load balancing



## fred974 (Apr 26, 2017)

Hi guys,

I wonder if someone could please help me.
I have 2 physical servers in the same datacenter.. One of them is curently our production server.
The second server is curently not doing anything other than costing money..
What would you advise be in making the best of my curent situation?

At the moment we use a zfs differential backup scrip that send all backup to offsite server..
If I set the second server as replication/failover i guess I have no downtime if thing go wrong but I am not sure i fully understand the differences between failover,replication and load balancing..

My understanding is this:
*Failover:* if production server die, them server 2 kick in and take over with no down time
*replication*: Server 2 is a exact copy of the production server and could be use to replace production server
*Load Balancing:* Provide high availability and boost service delivery but not sure what happen if one of ther servers dies..

The production server host the following:
FreeBSD 11 host
  jail1: web reverse proxy
  jail2: email server
  Jail3: database server
  Jail4: NS1 (bind)
  Jail5-20: wordpress backend

Thank you in adavance


----------



## SirDice (Apr 26, 2017)

Load-balancing balances traffic to 2 or more hosts. If one of those hosts fails (or if it's taken offline) it will balance the traffic over the remaining hosts.


----------



## fred974 (Apr 26, 2017)

SirDice said:


> Load-balancing balances traffic to 2 or more hosts. If one of those hosts fails (or if it's taken offline) it will balance the traffic over the remaining hosts.


So if I get it correctly, Load-balancing will also do replication? Will the server need to be setup identically


----------



## _martin (Apr 26, 2017)

You can have actually all 3 on an application you want to support. Those are technologies that provide certain level of redundancy and try to eliminate SPOF (single point of failure).  Word application here can be various things: virtual machine, database, SAP, ... 

Fail over means in case of an issue ( e.g. crashed node of a cluster, no network .. ) application will be handled (will run) by different node of a cluster. Depending on setup this can be with or without its downtime / intervention. 

Replication as in data replication means replicate (copy) data from site A to site B. Usually one wants this to be a different DC (data center) as you want to be able to survive disasters recovery. But local replications are not that uncommon either. 
You can have replication done by some 3rd party software or in more robust (and expensive) setup it can be done by storage. "Disks" on local machine are copies over the network (usually fabrics) to remote side, all handled by storage. You can loose the whole storage but you won't loose the application. 

Balancing is, as SirDice said, balancing traffic over more hosts. You have service running on more hosts that do the same tasks. You put balancing in front of it and let the balancer decide how that service is accessed (balanced). Balancer can be aware of a service failure and stop balancing to a host that is down. This is not redundancy of a service by any means. Failure of a service on one of the host means decreasing performance (less hosts to balance service to). But your service is not down, so it sometimes is thought of as 'redundancy'.


----------



## fred974 (Apr 26, 2017)

_martin said:


> You can have replication done by some 3rd party software or in more robust (and expensive) setup it can be done by storage.


What software would you advise on a zfs system?


----------



## SirDice (Apr 26, 2017)

fred974 said:


> So if I get it correctly, Load-balancing will also do replication? Will the server need to be setup identically


No, there's no replication. The load-balancing is typically done for access only (TCP connections, HTTP, that sort). For example, if you have three servers; server1, server2, server3. And you balance the HTTP(S) traffic only that traffic will get spread to the three servers. So the first request will go to server1, second request to server2, etc. You will need to make sure all three servers are the same and serve the same content. 

How we do it for example is using Puppet to make sure the configurations of the webservers are all the same (besides the obvious things like IP addresses). We also have a deployment script that basically copies the web content from Git to each webserver. All webservers are configured to use the same database server. With HAProxy the incoming web traffic is spread to 2 or more webservers. HAProxy also has a backup server configured in case _all_ webservers go down (for whatever reason, it really never happens, it's just a safety net). We typically have 4 webservers in the pool but we could run everything from just one (this server will get a really high load if that happens and the website will be quite slow but things will continue to work).

But with this setup I can easily take one of the webservers out of the pool to update it for example. In the mean time the remaining servers will continue to work and serve content. Once that webserver has been updated I simply add it back to the pool, and move to the next webserver. This all allows me to update _servers_ without taking the _service_ offline.


----------



## _martin (Apr 26, 2017)

fred974 said:


> What software would you advise on a zfs system?


Unfortunately I don't know. I only work with replications done on high-end storages. I would try to google something built on zfs send/receive. ZFS can send only snapshot so this could be a problem in your setup and may require some tuning ( place DB into the state where either it can create snapshot or ZFS can ).


----------



## SirDice (Apr 26, 2017)

The biggest question you probably need to ask is, what kind of data needs to be replicated. 

For our situation for example there's no need to replicate any data (or filesystems) because the data is stored in the databases, and every webserver has access to it. The website content is more or less replicated by the deployment scripts. Configurations are handled by Puppet.


----------



## fred974 (Apr 30, 2017)

SirDice said:


> We also have a deployment script that basically copies the web content from Git to each webserver.


When you update the website, do you make the changes in git and then push teh changes? or make changes on dev site,then push to git and the back to websers?

Do you use php-fpm for website isolation? is yes, do you create new php-fpm users via puppet?

Sorry..so many question but you really got m thinking and it make sense to do it this way... just need to understand a little bit more if you don't mind..

At the moment, I use 1 jail per domain.. I have about 20 jails so if webserver inside jail goes, the whole site goes (that never happened) and I cannot easily maintain the jail without downtime.. so your solution look attractive to me


----------



## SirDice (May 1, 2017)

fred974 said:


> When you update the website, do you make the changes in git and then push teh changes? or make changes on dev site,then push to git and the back to websers?


The latter. Developers work on a development server. Then commit their code and run a deployment script that pushes the changes from Git to the production servers. It could be a bit better separated but there's only one or two guys actually working on the site's code. 



> Do you use php-fpm for website isolation? is yes, do you create new php-fpm users via puppet?


Sites are all Ruby on Rails, no PHP.


----------

