2

Suppose I have nginx configured with 3 upstreams, and I make a request to download a file. One of the three upstreams will handle the request.

Will the response come directly from the upstream? or will the response come from the gateway (the machine which configures the upstreams)?

If it's the first case, how does this work? Is it similar to TCP Handoff, but at the HTTP level?

2

A setup where replies are sent directly from backends to the clients is called DSR load balancing. DSR is short for direct server return. In such a setup the load balancer simply forward every TCP packet to the backend selected for this connection by updating the destination address at the protocol layer used directly beneath IP, if the layer beneath IP isn't directly suitable an extra IP header can be inserted effectively tunneling packets from the frontend to the backend.

DSR is a bit more complicated network-wise, but it has performance benefits, and keeps the client IP directly visible to the backend.

I don't know for certain if nginx support DSR load balancing. A few searches suggest that it doesn't. Nginx forum threads from three years ago

1

In nginx, when you request to download a file, the gateway (your nginx front-end, I'd imagine) selects a backend for the request and queries that server for the file to send back to you. This data is passed through the gateway to the requester, so to the client it looks like the file is coming from the balancer rather than your backend. This is why Anycast DNS (or simple round-robin DNS) is typically used with CDNs rather than a direct balancer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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