Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Load Balancing gRPC &
HTTP/2 Across Kubernetes Pods.

gRPC multiplexes all 45,000 RPS over a single persistent HTTP/2 TCP subchannel per resolved IP, causing L4 AWS NLB to pin 100% of traffic on the original 4 pods after HPA scales to 24; switching to L7 Envoy/gRPC client-side round_robin with MAX_CONNECTION_AGE balances all 24 pods in <30s.
Start the journey5 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a single bottleneck threatens end-to-end availability, never rely on L4 load balancers for gRPC/HTTP2—use L7 per-RPC load balancing (Envoy or headless-service client round_robin) paired with jittered server MAX_CONNECTION_AGE + GOAWAY.

TL;DR30-second simplified summary
▾

Core Mechanics: Unlike HTTP/1.1 (which opens many short-lived TCP connections), gRPC over HTTP/2 multiplexes thousands of concurrent RPC streams over a single long-lived TCP subchannel per backend connection.

Visual & Structural Flow: Depicts HPA Scale 4 -> 24 Pods: L4 NLB Pinning vs. L7 Round-Robin + GOAWAY (gRPC Client (120x) -> Envoy L7 / Headless -> Orig 4 Pods -> New 20 Pods); gRPC Client (round_robin) / Envoy L7 -> 24 Pods w/ Jittered GOAWAY (120 gRPC Clients -> L7 Envoy / DNS -> 24 Backend Pods -> GOAWAY Grace).

Trade-Offs & Production: Using a standard Kubernetes ClusterIP (kube-proxy L4 iptables/IPVS) has the exact same TCP-pinning flaw as an AWS NLB—kube-proxy only picks a backend pod when the TCP socket is first established. Production gRPC platforms balance at Layer 7 (per-RPC) in one of two ways: Option A — L7 Proxy / Service Mesh (Envoy / Linkerd / Istio): Route gRPC through Envoy L7.

Failure Modes & Application: L7 HTTP/2 balancing and GOAWAY connection aging are essential across modern RPC meshes: High-QPS Microservice Meshes: Preventing HPA scale-out starvation in Envoy, Istio, or Linkerd.

Full walkthrough · 5 stages
01
STAGE 01 · WHY IT MATTERSL4 · FUNDAMENTALS

Why L4 load balancing fails for gRPC and HTTP/2.

Why this matters: The mechanism: understand how Why L4 load balancing fails for gRPC and HTTP/2 works from first principles.

Unlike HTTP/1.1 (which opens many short-lived TCP connections), gRPC over HTTP/2 multiplexes thousands of concurrent RPC streams over a single long-lived TCP subchannel per backend connection.

An AWS Network Load Balancer (L4) only load-balances new TCP connections.

02
STAGE 02 · IMPACTL5 · APPLIED DESIGN

What happens when HTTP/2 subchannels pin to old pods.

Why this matters: The problem: see what breaks without What happens when HTTP/2 subchannels pin to old pods under real concurrency or scale.

L4 connection-level balancing under HTTP/2 causes severe skew:

  1. 98% vs. 3% CPU Skew: Original 4 pods saturate and drop requests while 20 newly scaled pods sit idle.
  2. TLS 1.3 Reconnect Storms: Naively closing connections every few seconds without jitter triggers expensive TLS 1.3 mTLS handshake bursts.
L4 Pinning vs. L7 Per-RPC Balancing

HPA Scale 4 -> 24 Pods: L4 NLB Pinning vs. L7 Round-Robin + GOAWAY

gRPC Client (120x)Envoy L7 / HeadlessOrig 4 PodsNew 20 Pods1. L4 NLB: 100% of 45k RPS pinned!2. L7 / Client round_robindiscovers 24 IPs3. MAX_CONNECTION_AGE (5m+jit) ->GOAWAY4. Even ~1,875 RPS/pod (<10% skew)

L7 per-RPC balancing (or client-side round_robin on a K8s headless service) + jittered GOAWAY distributes 45k RPS evenly.

Engineering Decision Framework
Problem
How to implement Load Balancing gRPC & HTTP/2 Across Kubernetes Pods without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a single bottleneck threatens end-to-end availability, never rely on L4 load balancers for gRPC/HTTP2—use L7 per-RPC load balancing (Envoy or headless-service client round_robin) paired with jittered server MAX_CONNECTION_AGE + GOAWAY.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Load Balancing gRPC & HTTP/2 Across Kubernetes Pods experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · NAIVE SOLUTIONL5 · APPLIED DESIGN

Naive solution (and why ClusterIP or short client timeouts fail).

Why this matters: The problem: see what breaks without Naive solution under real concurrency or scale.

Think of Naive solution (and why ClusterIP or short client timeouts fail) as the intuition layer for Load Balancing gRPC & HTTP/2 Across Kubernetes Pods: The problem: see what breaks without Naive solution under real concurrency or scale.

Using a standard Kubernetes ClusterIP (kube-proxy L4 iptables/IPVS) has the exact same TCP-pinning flaw as an AWS NLB—kube-proxy only picks a backend pod when the TCP socket is first established.

Lifecycle & Failure Recovery

Naive solution (and why ClusterIP or short client timeouts fail)

probe passesburst > limitSIGTERM + preStopPending ScheduleReady (Serving)CFS / OOM RiskGraceful Drain
04
STAGE 04 · ENTERPRISE SOLUTIONL6 · SCALE & TRADE-OFFS

Enterprise solution: L7 Envoy / Headless Client round_robin + MAX_CONNECTION_AGE.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Production gRPC platforms balance at Layer 7 (per-RPC) in one of two ways:

  • Option A — L7 Proxy / Service Mesh (Envoy / Linkerd / Istio): Route gRPC through Envoy L7 listeners that terminate HTTP/2 and multiplex per-RPC across all 24 dynamic EndpointSlice IPs.
  • Option B — Client-Side Lookaside / Headless DNS round_robin: Expose a Kubernetes clusterIP: None headless service and configure Java (grpc-netty) and Python (grpcio) with defaultServiceConfig: {"loadBalancingConfig": [{"round_robin": {}}]} + periodic DNS refresh (30 s).
  • Jittered Server MAX_CONNECTION_AGE: Configure gRPC servers with maxConnectionAge = 5m + maxConnectionAgeGrace = 10s + random jitter so servers emit HTTP/2 GOAWAY frames cleanly—draining 2s in-flight RPCs and forcing clients to rebalance onto new pods without TLS storms.
L7 Per-RPC Load Balancing

gRPC Client (round_robin) / Envoy L7 -> 24 Pods w/ Jittered GOAWAY

120 gRPC ClientsJava + PythonL7 Envoy / DNSPer-RPC round_robin24 Backend Pods~1,875 RPS eachGOAWAY Grace5m+jit, 10s drain

1.Per-RPC Balancing: Distributes individual HTTP/2 streams across all 24 pods (<10% skew).

2.Jittered Age: Staggers MAX_CONNECTION_AGE so 120 clients don't TLS-handshake at once.

3.GOAWAY Drain: Finishes 2s in-flight unary RPCs cleanly before closing TCP sockets.

4.mTLS Preserved: Long-lived subchannels amortize TLS 1.3 handshakes over 5-minute windows.

L7 per-RPC balancing with jittered MAX_CONNECTION_AGE + GOAWAY achieves < 10% skew within 30s of HPA scale-out.

// Java grpc-netty: client-side round_robin + server MAX_CONNECTION_AGE
ManagedChannel channel = ManagedChannelBuilder
    .forTarget("dns:///payment-ledger-headless.prod.svc.cluster.local:9090")
    .defaultLoadBalancingPolicy("round_robin")
    .build();

Server server = NettyServerBuilder.forPort(9090)
    .maxConnectionAge(300 + ThreadLocalRandom.current().nextInt(60), TimeUnit.SECONDS)
    .maxConnectionAgeGrace(10, TimeUnit.SECONDS) // finishes 2s in-flight RPCs after GOAWAY
    .build();
05
STAGE 05 · SYSTEM DESIGN APPLICATIONSL7 · STAFF / PRINCIPAL

Where gRPC L7 Load Balancing applies in System Design.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

L7 HTTP/2 balancing and GOAWAY connection aging are essential across modern RPC meshes:

  • High-QPS Microservice Meshes: Preventing HPA scale-out starvation in Envoy, Istio, or Linkerd.
  • ML Inference & Feature Stores: Balancing heavy TensorFlow/Triton gRPC streams evenly across GPU replicas.
  • Headless Kubernetes Services: Client-side round_robin / xDS proxyless gRPC without sidecar overhead.
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does an AWS Network Load Balancer (L4) fail to distribute gRPC traffic onto 20 newly scaled Kubernetes pods?

Recommended Learning Flow