Architecture question - load balancer installed on all WEB API instances, but enabled only for one #2274
-
Hello folks, I searched a lot trough threads but I cannot find the question for the following scenario: Suppose there are 2 WEB API instances: WebApi1 and WebApi2 which are the same. The Yarp.Reverse proxy is installed in both instances - but only enabled in one. Is it possible to load balance between WebApi1 and WebApi2 when the gateway is embedded in WebApi1? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In theory, yes, but not with the built in load balancer, only with the IHttpForwarder. Say you want WebApi1 to handle 50% of traffic at endpoint "/location" and forward the other 50%. At the start of that endpoint you add code to check if load balancing is enabled for this instance. If it is, decide if this request should be forwarded. If so, call IHttpForwarder, otherwise let the endpoint run as usual. This only makes sense if the endpoint logic is significantly more expensive than the forwarding logic. Otherwise WebApi1 is doing twice as much work just to forward half of the requests. For truly balanced load you'd need a 3rd instance that only forwards to 1 or 2. |
Beta Was this translation helpful? Give feedback.
In theory, yes, but not with the built in load balancer, only with the IHttpForwarder.
Say you want WebApi1 to handle 50% of traffic at endpoint "/location" and forward the other 50%. At the start of that endpoint you add code to check if load balancing is enabled for this instance. If it is, decide if this request should be forwarded. If so, call IHttpForwarder, otherwise let the endpoint run as usual.
This only makes sense if the endpoint logic is significantly more expensive than the forwarding logic. Otherwise WebApi1 is doing twice as much work just to forward half of the requests. For truly balanced load you'd need a 3rd instance that only forwards to 1 or 2.