⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials ⚖️ Editorial Policy Standards & Trust 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Networking & Cloud DNS Interview Questions Scenario 63 of 64 in Networking & Cloud DNS
Senior DevOps / SRE Networking Traffic Routing & Load Balancing Production Runbook
🎯 Target Role / Context: Senior DevOps / SRE Infrastructure & Load Balancing Interview Scenario

Q: How do you configure HAProxy for end-to-end gRPC load balancing and ALPN HTTP/2 negotiation?

Master HAProxy interview questions on gRPC: ALPN h2 negotiation, proto h2 backends, long-lived stream timeouts, health checks and grpcurl verification.

#HAProxy #gRPC #HTTP/2 #ALPN #TLS #Networking
🎙️ Candidate Opening & Architectural Context
"Of all haproxy interview questions on modern protocols, gRPC trips people up because it needs HTTP/2 on both sides of the proxy. A gRPC client refuses to talk HTTP/1.1, so the TLS handshake must negotiate h2 through ALPN, and the backend connection must also speak h2, either as cleartext h2c or over TLS. I walk through four things: the frontend ALPN list, the backend protocol setting, timeouts for streams that stay open for hours, and a health check that does not break on HTTP/2. Then I prove each hop with grpcurl and curl instead of trusting the config."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Istio Service Mesh & Advanced Kubernetes Networking Course covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: Of all haproxy interview questions on modern protocols, gRPC trips people up because it needs HTTP/2 on both sides of the proxy. A gRPC client refuses to talk HTTP/1.1, so the TLS handshake must negotiate h2 through ALPN, and the backend connection must also speak h2, either as cleartext h2c or over TLS. I walk through four things: the frontend ALPN list, the backend protocol setting, timeouts for streams that stay open for hours, and a health check that does not break on HTTP/2. Then I prove each hop with grpcurl and curl instead of trusting the config.

1

Negotiate h2 on the Frontend with ALPN

ALPN is the TLS extension where the client offers protocols and the server picks one. I list h2 first and http/1.1 second so browsers and gRPC clients both work on the same port. Without the alpn keyword HAProxy does not advertise h2, the client falls back to HTTP/1.1, and gRPC clients fail with a protocol error.

frontend fe_grpc
    mode http
    bind :443 ssl crt /etc/haproxy/certs/api.pem alpn h2,http/1.1
    use_backend be_grpc if { hdr(content-type) -m beg application/grpc }
    default_backend be_web

# Prove the handshake picked h2:
openssl s_client -connect api.example.com:443 -alpn h2 </dev/null 2>/dev/null | grep -i alpn
# ALPN protocol: h2
2

Speak HTTP/2 to the Backend Servers

Terminating TLS and forwarding HTTP/1.1 would break gRPC, so the server line needs an explicit protocol. For plain gRPC servers inside a trusted network I use proto h2, which is cleartext HTTP/2 (h2c). When the backend also uses TLS, I use ssl with alpn h2 and verify the certificate. I choose leastconn because gRPC calls vary wildly in duration, and round robin would pile long streams onto one server.

backend be_grpc
    mode http
    balance leastconn
    server grpc1 10.0.2.11:50051 proto h2 check
    server grpc2 10.0.2.12:50051 proto h2 check

# TLS to the backend instead of h2c:
# server grpc1 10.0.2.11:50443 ssl verify required ca-file /etc/haproxy/ca.pem alpn h2 check
Advertisement
3

Tune Timeouts for Long-Lived Streams

Streaming RPCs can sit idle between messages for minutes. The defaults of 30 seconds that suit web traffic will reset those streams. I set timeout client and timeout server above the longest quiet gap my services have, and I keep timeout connect short so dead servers fail fast. timeout tunnel applies to upgraded connections, so I set it for completeness but I do not rely on it for h2 streams.

defaults
    mode http
    timeout connect 3s
    timeout client  10m
    timeout server  10m
    timeout tunnel  1h
    timeout http-keep-alive 30s

# gRPC status travels in trailers; do not add rules that buffer or rewrite the body
# on this backend, and leave compression off.
4

Choose a Health Check That Works with HTTP/2

A plain option httpchk sends an HTTP/1.x request, which an h2c-only server rejects, so the server flaps down for no real reason. The safest choice I know is the default TCP connect check on the server line, which proves the port accepts connections. If I need more, I point the check at a separate port where the service exposes a simple HTTP/1.1 health endpoint, using check port.

backend be_grpc
    default-server inter 3s rise 2 fall 3
    server grpc1 10.0.2.11:50051 proto h2 check
    server grpc2 10.0.2.12:50051 proto h2 check port 8081

# Port 8081 serves an HTTP/1.1 endpoint, so add:
# option httpchk GET /healthz
# http-check expect status 200
5

Verify Each Hop with grpcurl and curl

I never call this done until a real client succeeds. grpcurl exercises the gRPC path including the standard health service, and curl with --http2 shows which protocol version the proxy actually spoke to me. I also watch show servers state for the backends so I know the checks agree with the client results.

grpcurl -d '{}' api.example.com:443 grpc.health.v1.Health/Check
# {
#   "status": "SERVING"
# }

curl --http2 -s -o /dev/null -w '%{http_version}\n' https://api.example.com/
# 2

echo "show servers state be_grpc" | socat stdio /run/haproxy/admin.sock
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"For haproxy interview questions on gRPC, the answer is h2 on every hop: alpn h2,http/1.1 on the bind line, proto h2 or ssl with alpn h2 on the server lines, leastconn for uneven call lengths, and generous client and server timeouts for streams. Finish by proving it with grpcurl and curl --http2."
⚡ 60-Second Elevator Pitch Talking Points
  • gRPC requires HTTP/2, so I advertise h2 through ALPN on the TLS bind line and keep http/1.1 as a fallback for other clients.
  • Backend servers get proto h2 for cleartext h2c, or ssl with alpn h2 when the internal hop is encrypted.
  • Streams can stay idle for minutes, so timeout client and timeout server must exceed the longest quiet gap, and I use leastconn to balance uneven calls.
  • I check health with a TCP connect or a separate HTTP/1.1 port, then verify with grpcurl and curl --http2.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Omitting alpn on the bind line HAProxy then does not offer h2 during the TLS handshake, so gRPC clients fall back to HTTP/1.1 and fail with a protocol error.
  2. Terminating TLS and forwarding HTTP/1.1 to a gRPC server gRPC servers expect HTTP/2 framing and trailers, so requests are rejected or the status trailer never arrives.
  3. Leaving the 30 second web timeouts on a streaming backend Idle bidirectional streams get reset in the middle of a session and clients see sporadic UNAVAILABLE or CANCELLED errors.
  4. Using option httpchk against an h2c-only backend The HTTP/1.x probe is refused, so healthy servers are marked down and traffic collapses onto fewer nodes.
Advertisement
Want more Networking & Cloud DNS scenarios?
Explore our complete collection of scenario-based Networking & Cloud DNS interview runbooks.
Browse All Networking & Cloud DNS Questions →