Lesson 7 of 9 · 27m
Load Balancing Long-Lived gRPC Connections
Understand why HTTP/2 connection reuse defeats naive L4 balancing, then choose client-side, proxyless, or L7 strategies that spread RPCs rather than TCP sessions.
A team once told me their gRPC deployment was broken because one pod served 80 percent of traffic while eleven others idled. Nothing was broken. Kubernetes had balanced TCP connections perfectly. gRPC then reused those long-lived HTTP/2 connections so efficiently that random connection placement became permanent RPC placement. That is the entire problem in one sentence.
Why L4 balancing is not enough
A layer-4 balancer sees a TCP connection, not individual RPCs:
client A -> pod 1 one connection, 10,000 RPCs/hour
client B -> pod 2 one connection, 20 RPCs/hour
client C -> pod 1 one connection, 8,000 RPCs/hourTraditional HTTP/1.1 often created enough connection churn to rebalance accidentally. gRPC is designed to avoid churn. Efficiency and balance are now in tension.
Client-side balancing
gRPC clients can resolve backends and choose among them using policies such as round_robin:
dns:///billing.internal:443
round_robinThis spreads RPC substreams across multiple connections. It works well inside controlled environments where service discovery is accurate. It also moves operational responsibility into every client runtime and version.
L7 proxy balancing
Envoy, Linkerd, and similar proxies understand HTTP/2 streams and can balance each RPC:
type: logical_dns
lb_policy: ROUND_ROBIN
http2_protocol_options: {}This centralizes behavior and supports zone-aware routing, outlier detection, circuit breaking, and consistent observability. The cost is another production system you must operate correctly.
Kubernetes specifics
A headless Service can expose pod IPs for client-side discovery. xDS-enabled meshes can supply backends dynamically. If using a regular ClusterIP with kube-proxy, remember that it is mostly connection-oriented from the client's perspective. Long-lived clients can stick to old backends until reconnect or endpoint changes force redistribution.
Draining is part of balancing
Deployments need servers to stop accepting new work while existing streams finish. gRPC supports graceful stop patterns, but your orchestration must allow enough time. Long streams complicate this: sometimes the right answer is a maximum stream lifetime so clients reconnect naturally before termination deadlines.
Health checking must reflect serving reality
A process listening is not necessarily serving. Use the gRPC health checking protocol or mesh-native checks that reflect dependency readiness. Do not mark a server unhealthy for a single downstream error if doing so causes a traffic stampede; distinguish load-balancer health from deep application correctness.
Field notes
- Rebalancing rarely happens by magic after scale-out unless connections or policies change.
- Measure RPC distribution, not just TCP connection distribution.
- Client behavior matters: a few large clients can dominate even with perfect server capacity.
- Connection max age can force periodic redistribution, but it is a blunt instrument.
- Load balancing, retry, and timeout policies interact. Tune them together, not in separate dashboards.
Was this lesson helpful?