4

We would like to send the request received by an Apache proxy to all of a set of downstream servers (in fact, also proxies, but I don't think this matters).

We know that all but at most one of these requests will fail, for a variety of reasons (server at that IP doesn't exist, is not listening on the right port, or the credentials are wrong).

We know that for one server, the request should work (but may not - the server may be powered off, not working correctly, overloaded etc). We don't know which of the servers this will be for any one request.

So we'd like to return the one correct response, if it happens, or if not any of the error responses (or a fixed failure response) should be returned.

Any ideas? It's not the most complex app to write if we need to do it from scratch, but we'd prefer to use Apache (which is already in place in our solution) if we can.

  • Looks more like a job for `haproxy`, not `apache`. – wurtel Nov 28 '14 at 13:25
  • 1
    Thanks. After a (very quick) look at the manual I don't see how to send the request on to all downstream servers rather than load balancing across them, but I'll take another look – The Archetypal Paul Nov 28 '14 at 14:40
  • You don't send the request to all downstream (backend) servers; instead you let haproxy check at regular intervals which servers are available, and then real requests will only be sent to one of the available servers. Sending all incoming requests to all backend servers is quite a massive waste of resources IMHO. – wurtel Nov 28 '14 at 14:49
  • 1
    Unfortunately it's not that simple. As I mentioned, the downstream servers are also proxies - and the actual destination server is one of several million devices. The actual device is behind one of the proxies, but I don't know which one. So I'm not testing if the proxies are available, but if the destination behind them is. – The Archetypal Paul Nov 28 '14 at 14:51

2 Answers2

6

covener is correct, mod_proxy is not able to do this.

However, Gor was written to do exactly this.

Hat tip to Arthur Lutz for posting the answer here.

chmac
  • 977
  • 1
  • 7
  • 16
  • It's getting close, but not quite what I need. I need the responses to the multiple servers to be merged and if one (or more, in general, but it will only be one in my case) succeeds (2xx) then to return that. It's not clear what Gor does with the responses - drop them on the floor, probably? – The Archetypal Paul Dec 07 '14 at 16:54
  • Yeah, gor ignores the responses and always sends a 200 with a body OK. It also has an issue forwarding POST bodies, but that's probably a bug. Sounds like the merging of responses is a pretty rare use case, and will probably need custom code. Would be easy enough to build mind you... – chmac Dec 07 '14 at 17:35
  • Yes, I accept it's pretty rare :) It's not too difficult to write, as I say in the question. It's a bit more tricky to make it work with a few million end points the other side of the proxies (and the number of simultaneous connections that implies) but it's a good fit for something like node.js – The Archetypal Paul Dec 07 '14 at 17:39
  • Hahaha, writing it, and getting it to work at scale, I will agree, are two entirely different tasks. Best of luck. :-) – chmac Dec 07 '14 at 17:58
  • I made it Product's problem (I'm in Deployment :-P) – The Archetypal Paul Dec 07 '14 at 19:25
5

No, Apache's mod_proxy simply cannot send a request to multiple origin servers.

covener
  • 1,665
  • 9
  • 15