Cloud Infrastructure··2 min read

Fixing gRPC HTTP/2 Single-Connection Bottlenecks Behind Kubernetes Headless Services (3.8x Throughput Gain)

Shafikul Islam

Shafikul Islam

Backend & Cloud Infrastructure Engineer · Infrastructure & Cloud Team Lead

Fixing gRPC HTTP/2 Single-Connection Bottlenecks Behind Kubernetes Headless Services (3.8x Throughput Gain)

Why 7 Out of 8 Kubernetes Pods Sat Idle Under Load

When we migrated an internal high-throughput scoring service from REST/HTTP1.1 to gRPC (HTTP/2) on Kubernetes, our Horizontal Pod Autoscaler scaled the deployment from 2 pods to 8 pods during peak traffic.

Yet P99 latency kept climbing. Inspecting kubectl top pods revealed the problem immediately: two pods were pinned at 95% CPU, while the other six newly scaled pods sat at 2% CPU.


1. L4 TCP Load Balancing vs L7 HTTP/2 Multiplexing

By default, a Kubernetes ClusterIP Service operates at Layer 4 (TCP). When a Go gRPC client dials scoring-svc.prod.svc.cluster.local:50051, kube-proxy picks a single backend pod and opens one long-lived TCP connection.

Because HTTP/2 multiplexes thousands of concurrent RPC requests over that single TCP connection, the client keeps sending 100% of future requests to that one pod forever. New pods spun up by HPA never receive a TCP handshake.


2. Switching to a Kubernetes Headless Service (clusterIP: None)

Instead of hiding pod IPs behind a single virtual ClusterIP, we exposed the gRPC deployment via a Headless Service so CoreDNS returns the A records of all ready pod IPs:

apiVersion: v1
kind: Service
metadata:
  name: scoring-grpc-headless
  namespace: prod
spec:
  clusterIP: None
  selector:
    app: scoring-grpc
  ports:
    - name: grpc
      port: 50051
      targetPort: 50051

3. Enabling Client-Side Round-Robin + MaxConnectionAge

Next, we configured the Go gRPC client to use the dns:/// resolver with round_robin load balancing, and added MaxConnectionAge on the server so clients periodically re-resolve DNS when new pods scale up:

conn, err := grpc.NewClient(
    "dns:///scoring-grpc-headless.prod.svc.cluster.local:50051",
    grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`),
    grpc.WithTransportCredentials(insecure.NewCredentials()),
)
server := grpc.NewServer(
    grpc.KeepaliveParams(keepalive.ServerParameters{
        MaxConnectionAge:      2 * time.Minute,
        MaxConnectionAgeGrace: 10 * time.Second,
    }),
)

CPU utilization immediately flattened to an even 31% across all 8 pods, and total service throughput jumped by 3.8x.

Infrastructure & PostgreSQL Advisory

Scaling Infrastructure or Diagnosing P95 Latency?

I help engineering teams diagnose PostgreSQL indexing bottlenecks, concurrency limits, and K3s/Docker deployments. Book a 20-minute call with me to review your setup.

Related Technical Articles