Http2 load balancer by using L4

grpcload balancing

As far as I known, L4 load balancer maintains 2 TCP connections:

  • One is from front side to Load balancer
  • LB terminate above connection, create new TCP connection , change IP/Port of TCP packet to forward to backend.

In HTTP2/gGPRC, client-server will maintains a single long live connection.
If we use L4, this connection will be the first one which is mentioned above.

In some articles, I read that although there are multiple deployed backend servers, once one client makes first request to one backend, this pair client-backend will be kept for all successive requests. That means other backends are unused.

Here is one of articles:
https://blog.bugsnag.com/envoy/

gRPC uses the performance boosted HTTP/2 protocol. One of the many
ways HTTP/2 achieves lower latency than its predecessor is by
leveraging a single long-lived TCP connection and to multiplex
request/responses across it. This causes a problem for layer 4 (L4)
load balancers as they operate at too low a level to be able to make
routing decisions based on the type of traffic received. As such, an
L4 load balancer, attempting to load balance HTTP/2 traffic, will open
a single TCP connection and route all successive traffic to that same
long-lived connection, in effect cancelling out the load balancing.

I am really unclearly this point.
Anybody could please explains more details? Many appreciate! Thanks

Best Answer

If you have more clients than backend servers, this might not be a problem. Try a least connection algorithm, like "leastconn" from haproxy. Making up an example, maybe your 10 switches stream metrics data via gRPC into 3 backend nodes of your monitoring platform. Every backend gets some work.

Even if you only have one connection, this still might not be a problem, assuming a single node can handle it. Effectively this becomes an active/passive configuration. Whether that host kept idle is worth the expense is your decision.

That said, sometimes load balancers inspect the application at layer 7. A common HTTP example is cookie affinity. Layer 7 is not required for long lived connections, however.

Related Topic