0

I am building my own load balancer in C++. But I lack some fundamental knowledge of how requests/responses flow in such routing configuration. Suppose I have application at www.application.com and that DNS returns ip-address of Load balancer when requested. Client's ip is client_ip, balancer's one is balancer_ip and server's - server_ip. So here is sequence of packets generated in a network:

1) The first packet is generated by client requesting load balancer:

+-----------+-------------+---------+
|  Source   | Destination | Request |
+-----------+-------------+---------+
| client_ip | balancer_ip | /hello  |
+-----------+-------------+---------+

2) The second one is generated by balancer making request to server and putting client_ip into X-Forwarded-For header:

+-------------+-------------+---------+-----------------+
|   Source    | Destination | Request | X-Forwarded-For |
+-------------+-------------+---------+-----------------+
| balancer_ip | server_ip   | /hello  | client_ip       |
+-------------+-------------+---------+-----------------+

3) The server is receives request and makes response back to load balancer. X-Forwarded-For remains the same.

+-----------+-------------+------------------+-----------------+
|  Source   | Destination |     Response     | X-Forwarded-For |
+-----------+-------------+------------------+-----------------+
| server_ip | balancer_ip | response_message | client_ip       |
+-----------+-------------+------------------+-----------------+

4) Balancer receives response from server and creates its own response back to client, by taking client's ip-address from X-Forwarded-For header and putting it into destination:

+-------------+-------------+------------------+
|   Source    | Destination |     Response     |
+-------------+-------------+------------------+
| balancer_ip | client_ip   | response_message |
+-------------+-------------+------------------+

Suppose all communcation is performed in HTTP. Is this a correct way of performing redirects between client - load balancer - server? I have looked through standard request/response fields and X-Forwarded-For wasn't in the list of standard and non-standard responses. Also if this is the correct way, won't such popular frameworks such as Spring, Django, Node.js discard X-Forwarded-For header?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.