OptimalBits / redbird

A modern reverse proxy for node
BSD 2-Clause "Simplified" License
4.41k stars 280 forks source link

Is there a way to implement failover if a primary server does not accept the request? #65

Open MostHated opened 8 years ago

MostHated commented 8 years ago

Hello, I was wondering if Redbird was capable of handling failover? My company just got a second fiber line put in that we have setup for failover in the firewall so that if the primary connection goes down it switches over to the secondary, the only issue though is with DNS for all of our internally hosted sites. DNS only has the ability to basically load balance with multiple A records.

My plan is to use a droplet on DigitalOcean to basically be a gateway to all of our sites to solve this issue. It can test externally if the primary connection is working, and if so it can send the requests there, but if it detects that it is down, it can then send the request to the secondary IP, which I can then setup in the firewall to send the requests to the appropriate servers internally.

So the question is, is there a built in way currently to do this, or will I have to try and implement some of my own if/then logic to decide where to set the proxy.register command to?

manast commented 8 years ago

I guess that if this was implemented: https://github.com/OptimalBits/redbird/blob/master/lib/proxy.js#L229 it would just be a matter of using the load-balancer in redbird (i.e. registering the same route pointing to two different ip addresses)

manast commented 8 years ago

(we accept patches :)

MostHated commented 8 years ago

Yeah, I saw the load balancing, I guess a switch could be put in to select either failover, load balancing, or both. I am not great with programming, but do have some experience and am trying to learn and get better, which is why if there was not a way to do it that was already built in, I was going to try and make one. : )

manast commented 8 years ago

its mostly that currently the load balancer does not handle well targets that do not respond, so this is actually I need to implement. Maybe next week...

MostHated commented 8 years ago

How would I go about dynamically register and then unregister a proxy? Such as, register a proxy to an IP, if it does not respond to either ping or some other sort of connection attempt, then unregister that proxy for now, and then register a new one. Would I be able to do something similar to the below if I implement some sort of way to check (just as a small example)? if (host1Connection == true){ proxy.register("example.com", "http://1.1.1.1") } else { proxy.register("example.com", "http://1.1.1.2" ) }

Or do you have to somehow "unregister" the first proxy?

manast commented 8 years ago

you need to unregister: https://github.com/OptimalBits/redbird#unregister You can check how the etcd backend is implemented for inspiration...

dimasahmad commented 7 years ago

Any updates on the failover support?

gustter commented 5 years ago

Hi there! Any update on the failover. I think it's a critical functionality in load balancing and it would be very cool if the module had it.