Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Say someone makes a http get/post request to api.example.com/a/b

Now say I have 10 servers setup as my backend servers. I want ha proxy to act as a load balancer and during the request handshake respond with:

apiX.example.com/a/b

where X is a number in the range 1..10

If haproxy isn't the right tool for this, what would you suggest?

What benefits to hardware based load balancers offer?

Update

Normally from what I understand of proxies is that haproxy will take a request, and proxy it to a backend server, wait for the response, and then send the response to the client. The client has no idea which backend server responded to their request.

Now if I have 10 backend servers, the haproxy server will be overloaded since it will have to handle the throughput of 10 servers traffic/bandwidth since all requests and responses are going through the haproxy server.

I am curious if haproxy could simple hand of the request to a particular backend server, and then the client will talk directly with the backend server (the backend will be publicly accessible at api3.example.com or api[1..10].example.com)

The client will be making only a single request, so the session will last for a single request only where the client makes a http get/post request and waits for a response, that's it.

share|improve this question
    
Can you provide more details? I'm not sure that I get your proposition. –  Marcelo Bittencourt Jan 2 '12 at 3:16
    
@MarceloBittencourt i've updated my question. –  Blankman Jan 2 '12 at 3:26
    
It may be possible, in the first hit the chosen server can create a redirect (302) to himself, and all the conversation later is direct to the server. But I don't think that you can overload haproxy so easily. My main HAProxy gets 11mi hits/day , and it's running in a single proc VPS server with only 1G RAM –  Marcelo Bittencourt Jan 2 '12 at 3:46
    
@MarceloBittencourt but if clients are uploading files that are 20-50kb in size, that is allot of data going through a single server no? –  Blankman Jan 2 '12 at 3:50
2  
I believe that it can handle it. near half of my 11mi hits are images, and some other static content. did you know that Stack Exchange uses HAProxy? blog.serverfault.com/2011/09/30/… –  Marcelo Bittencourt Jan 2 '12 at 4:09

2 Answers 2

This can be possible or not depending on your setup. If your clients are configured to use a proxy server (which is HAproxy) or you are always transparently proxying all requests to HAproxy, then apparently your idea can not be implemented.

On the other hand, if the name api.example.com points to Haproxy host itself. You can use redirect to send 302 HTTP codes to your clients. The redirects should point to one of the backend servers. Then, you need to find a way to use different redirect statements for different backend servers based on some criteria. You can choose something changing randomly such as source port or source IP.

share|improve this answer
    
Yes api.example.com will point to haproxy itself, and yes I will distribute load (initially) doing round robin. –  Blankman Jan 2 '12 at 13:21

Have you considered having your backend servers append a header with their own header with server id/host name in the response?

Update 10/8/12: HAProxy 1.4.20 added an option http-send-name-header, which adds the backend server as a hostname on responses.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.