📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What do HTTP/2 and HTTP/3 change for API performance? Explain multiplexing, header compression and head-of-line blocking at the HTTP and TCP level, how you enable each in Kestrel and HttpClient on .NET 10, and when they make a measurable difference.

Covers HTTP/2 multiplexing and HPACK, TCP head-of-line blocking, HTTP/3 over QUIC (QPACK, 0-RTT, connection migration), enabling them in Kestrel and HttpClient on .NET 10, and when the gain is real.

Mid-Level Theory Intermediate api-performance http2 http3 kestrel performance quic

🎯 Key points

  • HTTP/1.1: one in-flight request per connection, so browsers open ~6 connections per host and requests queue
  • HTTP/2: binary framing, many streams multiplexed on one TCP connection, HPACK header compression, per-stream and connection flow control; server push is deprecated and removed from browsers
  • HTTP/2 removes HTTP-level head-of-line blocking but one lost TCP packet still stalls every stream
  • HTTP/3 runs over QUIC on UDP: per-stream loss recovery, 1-RTT (0-RTT resume) handshake, connection migration, QPACK
  • QUIC mandates TLS 1.3 and encrypts transport headers; 0-RTT data is replayable, so only idempotent requests should use it
  • Kestrel: HTTP/1.1 and HTTP/2 by default on HTTPS; HTTP/3 needs Protocols = Http1AndHttp2AndHttp3, MsQuic (shipped with .NET on Windows, libmsquic package on Linux) and an Alt-Svc upgrade
  • HttpClient defaults to HTTP/1.1; set DefaultRequestVersion and VersionPolicy; PublishTrimmed/PublishAot disable HTTP/3 in HttpClient by default in .NET 10
  • Biggest gains: high RTT (regional or overseas users), lossy mobile networks, many parallel small requests, gRPC; measure per protocol at each hop

⏱ 30-second answer

HTTP/2 sends many requests as multiplexed streams over one TCP connection, with binary framing and HPACK header compression, so you stop paying for extra connections and HTTP/1.1's one-request-at-a-time queue. But it still runs on TCP, so one lost packet stalls every stream: TCP head-of-line blocking.

HTTP/3 moves to QUIC over UDP with TLS 1.3 built in: each stream recovers from loss on its own, the handshake is faster (1-RTT, 0-RTT on resume), and connections survive a network change.

In .NET 10, Kestrel serves HTTP/1.1 and HTTP/2 by default. HTTP/3 is a one-line opt-in: MsQuic ships with .NET on Windows, and on Linux you install the libmsquic package. The gain is real on high-latency, lossy mobile networks with many parallel requests and for gRPC; for a single big response inside one Azure region it is usually noise. Measure per protocol before you claim it.

🗣 Full answer (senior)

How I would answer this in an interview

"HTTP/1.1 can only have one request in flight per connection, so clients open several connections and requests still queue behind each other. HTTP/2 fixes that at the HTTP layer: requests become streams of binary frames interleaved on one TCP connection, and headers are compressed with HPACK, which matters when every request carries a 1 KB bearer token. But TCP delivers bytes in order, so if one packet is lost, every stream waits for the retransmit. That is TCP head-of-line blocking, and on a lossy mobile link HTTP/2 can be worse than several HTTP/1.1 connections.

HTTP/3 solves that by running over QUIC on UDP. QUIC does its own reliability per stream, so a lost packet only stalls its stream. It folds TLS 1.3 into the transport handshake, so a new connection costs one round trip, and resumption can be zero. It also uses connection IDs, so a phone moving from Wi-Fi to 5G keeps its connection. In .NET 10, Kestrel serves HTTP/1.1 and HTTP/2 on HTTPS endpoints by default. HTTP/3 is opt-in: you set Protocols = Http1AndHttp2AndHttp3, need MsQuic (bundled on Windows, libmsquic on Linux), and clients discover it through the Alt-Svc header. HttpClient still defaults to HTTP/1.1, so you set DefaultRequestVersion and VersionPolicy yourself, and in .NET 10 trimmed or Native AOT apps have HTTP/3 off in HttpClient unless you turn it back on.

The mistake I see is enabling HTTP/3 and expecting the p95 to halve. Between two services in the same Azure region, with sub-millisecond RTT and almost no loss, the difference is noise; and often a load balancer in the middle terminates the connection and speaks HTTP/1.1 to the app anyway. Protocols help when round trips and loss hurt; measure where your users are."


Protocol comparison

HTTP/1.1 HTTP/2 HTTP/3
Transport TCP TCP QUIC (UDP)
Requests per connection 1 at a time Many streams Many streams
Header compression None HPACK QPACK
HOL blocking HTTP and TCP TCP only None across streams
New connection TCP + TLS (2–3 RTT) Same 1 RTT, 0-RTT resume
Network change New connection New connection Connection migration

When it makes a measurable difference

Situation Expected gain
Mobile clients, high RTT, packet loss, many small parallel calls HTTP/3 can cut tail latency noticeably
SPA loading many assets/API calls from one host HTTP/2 removes connection limits
gRPC HTTP/2 is required; HTTP/3 optional
Service-to-service in one region, few large calls Little or none

Production example

A field-service app used by technicians in regional Australia made 30 small API calls on its home screen. Enabling HTTP/2 at Azure Front Door dropped home-screen p95 from 3.1 s to 1.9 s; adding HTTP/3 at the edge brought p95 on poor connections down a further ~20%, while the median barely moved. Inside the region, app-to-app calls stayed on HTTP/1.1 with no measurable loss.

🔍 What the interviewer is checking

Checks that the candidate understands what each HTTP version changes at the transport level, can enable them in .NET, and knows when the gain is real versus marketing.

Green flags

  • Explains TCP head-of-line blocking and why QUIC fixes it
  • Knows Kestrel defaults and that HTTP/3 is opt-in with MsQuic
  • Mentions HttpClient's HTTP/1.1 default and version policy
  • Talks about proxies, fallback and measuring per protocol

Red flags

  • "HTTP/2 is just faster" with no mechanism
  • Thinks HTTP/2 fixed all head-of-line blocking
  • Ignores proxies terminating the protocol

📚 Learn in depth

1. HTTP/1.1 limits

conn 1: [GET /a ......][GET /d ......]
conn 2: [GET /b ........................]   <- slow response blocks this conn
conn 3: [GET /c ..][GET /e ..]

One request per connection at a time (pipelining exists but is effectively unused). Browsers cap at ~6 connections per host, so extra requests queue.

2. HTTP/2: streams, frames, flow control and priority

TCP connection
  | HEADERS(s1) | HEADERS(s3) | DATA(s1) | DATA(s3) | DATA(s1) | ...
  • Each request/response is a stream with an odd ID; frames from different streams interleave.
  • HPACK compresses headers with a static table, a dynamic table and Huffman coding; repeated Authorization and cookies cost a few bytes after the first request.
  • Flow control works per stream and per connection with WINDOW_UPDATE frames. If the receive window is too small for the bandwidth-delay product, a fast link sits idle waiting for window updates. Kestrel exposes Limits.Http2.InitialConnectionWindowSize (default 1 MB) and InitialStreamWindowSize (default 768 KB); large uploads or streaming over high-RTT links may need more, at the cost of memory per connection.
  • SETTINGS_MAX_CONCURRENT_STREAMS limits parallel streams (Kestrel Limits.Http2.MaxStreamsPerConnection, default 100).
  • Prioritisation: the original HTTP/2 priority tree was complex and inconsistently implemented; RFC 9218 replaces it with the simpler Priority header (urgency and incremental) used by HTTP/3 too. Don't rely on server-side priority for API latency.
  • Server push is effectively dead (browsers removed it); don't design around it.

3. TCP head-of-line blocking

TCP guarantees in-order bytes. If segment 41 is lost, segments 42–60 sit in the kernel buffer until 41 is retransmitted, even if they belong to other streams. With 2% loss, one HTTP/2 connection can underperform six HTTP/1.1 connections.

4. QUIC and HTTP/3

UDP datagrams
  QUIC packet [conn-id][stream 1 frame][stream 5 frame]
  -> lost packet affects only streams 1 and 5
  • Streams are first-class in the transport; loss recovery and flow control are per stream and per connection inside QUIC, so HTTP/3 itself doesn't need HTTP/2-style window frames.
  • TLS 1.3 is mandatory and built into the handshake; most transport headers are encrypted. Handshake in 1 RTT, 0-RTT for resumption (0-RTT data can be replayed, so only safe/idempotent requests should use it).
  • Connection IDs allow migration across IP changes.
  • Runs in user space (MsQuic in .NET), which costs more CPU per byte than kernel TCP today.
  • Some corporate networks block UDP 443, so clients must fall back.

5. .NET 10 specifics

  • Kestrel: default protocols on HTTPS endpoints are HTTP/1.1 and HTTP/2 (negotiated with ALPN). HTTP/2 without TLS (h2c) needs Protocols = Http2 explicitly and is mainly for gRPC behind a proxy. HTTP/3 requires Http1AndHttp2AndHttp3, TLS, and MsQuic (shipped with .NET on Windows; install libmsquic from the Microsoft package repository on Linux); if it is missing, Kestrel logs it and falls back. Kestrel sends Alt-Svc so clients can upgrade on later requests.
  • HttpClient: default DefaultRequestVersion is 1.1. Set HttpVersion.Version20 or Version30 with HttpVersionPolicy.RequestVersionOrLower to fall back gracefully. In .NET 10, PublishTrimmed or PublishAot disable HTTP/3 in System.Net.Http by default (a feature switch can re-enable it).
  • Behind proxies: Azure App Service, Front Door, Application Gateway, nginx and YARP may terminate HTTP/2/3 at the edge and talk HTTP/1.1 to your app. What matters is the leg with high RTT, usually client to edge.

6. Where the gains show up

Client RTT Typical effect
Same Azure region <2 ms Negligible
Sydney user to Australia East 5–20 ms Small; HTTP/2 helps many-call pages
Perth or regional 4G to Australia East 50–100 ms, some loss HTTP/2 and HTTP/3 help noticeably; HTTP/3 helps the tail
Overseas user to Australia East 150–300 ms Handshake savings and an edge PoP matter most

7. Measuring

  • Load test each protocol (k6 supports HTTP/2; h2load and curl --http3 for HTTP/3) with realistic RTT and loss injected (tc netem on Linux).
  • Compare client p50/p95/p99 and server CPU per request.
  • In production, log the negotiated protocol (HttpContext.Request.Protocol) and split latency by it.

Try it yourself

  1. Run Kestrel with HTTP/3 enabled and call it with curl --http3 -v; check the Alt-Svc header on an HTTP/2 response first.
  2. Log Request.Protocol per request and chart the share of each version.
  3. Use tc qdisc add dev lo root netem delay 80ms loss 2% and compare HTTP/1.1, HTTP/2 and HTTP/3 with a load tool.
  4. Make 50 parallel small requests from HttpClient on HTTP/1.1 vs HTTP/2 and watch http.client.open_connections with dotnet-counters.
  5. Publish with PublishAot=true and confirm HttpClient HTTP/3 behaviour changes.

💻 Code

Enabling HTTP/3 in Kestrel and asking for it from HttpClient with a safe fallback:

// Program.cs (server)
using Microsoft.AspNetCore.Server.Kestrel.Core;

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(k =>
{
    k.ListenAnyIP(5001, listen =>
    {
        // Keep 1.1 and 2 for clients and networks that block UDP 443.
        listen.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
        listen.UseHttps(); // HTTP/3 requires TLS 1.3
    });
});

var app = builder.Build();

// Log which protocol was negotiated so latency can be split by it.
app.Use(async (ctx, next) =>
{
    using var _ = app.Logger.BeginScope(new Dictionary<string, object> { ["HttpProtocol"] = ctx.Request.Protocol });
    await next(ctx);
});

app.MapGet("/ping", (HttpContext ctx) => Results.Ok(new { protocol = ctx.Request.Protocol }));
app.Run();
// Client registration in another service
using System.Net;

builder.Services.AddHttpClient<CatalogueClient>(c =>
{
    c.BaseAddress = new Uri("https://catalogue.example.com.au");
    c.DefaultRequestVersion = HttpVersion.Version30;
    c.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower; // fall back to 2 or 1.1
});

public sealed class CatalogueClient(HttpClient http)
{
    public async Task<string> PingAsync(CancellationToken ct) =>
        await http.GetStringAsync("/ping", ct);
}
# Verify from the command line
curl -sI --http2 https://localhost:5001/ping | grep -i alt-svc
curl -s --http3 https://localhost:5001/ping

⚠ Common mistakes

  • Mistake: Optimising without measuring: enabling HTTP/3 and declaring victory. Why it is wrong: in-region traffic often shows no gain, and QUIC costs more CPU. Instead: load test each protocol with realistic RTT and loss, and compare client p95.
  • Mistake: Micro-optimising protocol settings for an internal batch job that makes a few large calls. Why it is wrong: round trips are not its bottleneck. Instead: spend effort where RTT and many small calls dominate.
  • Mistake: Assuming HTTP/2 removes all head-of-line blocking. Why it is wrong: TCP still stalls every stream on one lost packet. Instead: consider HTTP/3 for lossy client networks.
  • Mistake: Enabling only HTTP/3. Why it is wrong: many networks block UDP 443 and clients need TCP fallback. Instead: Http1AndHttp2AndHttp3 and let Alt-Svc upgrade.
  • Mistake: Misconfiguring the load balancer or proxy: an L4 balancer that pins long-lived HTTP/2 connections to one instance, a proxy that doesn't forward ALPN or strips Alt-Svc, or a firewall dropping UDP 443. Why it is wrong: the protocol never reaches the app, or all traffic lands on one pod. Instead: check each hop's supported protocols, use L7 balancing for HTTP/2/gRPC, and log Request.Protocol in the app.
  • Mistake: Forgetting HttpClient defaults to HTTP/1.1. Why it is wrong: service-to-service calls never use HTTP/2 multiplexing. Instead: set DefaultRequestVersion and VersionPolicy.
  • Mistake: Using a single HTTP/2 connection for very high-volume gRPC. Why it is wrong: requests queue beyond ~100 concurrent streams. Instead: EnableMultipleHttp2Connections = true.
  • Mistake: Designing around HTTP/2 server push. Why it is wrong: browsers have removed it. Instead: use preload hints (103 Early Hints, Link: rel=preload) or fewer, larger requests.

🏛 Senior insight: trade-offs

Protocol upgrades are a network-latency tool, not a server-speed tool. A senior asks where the round trips and losses are: almost always the client-to-edge leg. That's why the strategic move is usually architectural: terminate HTTP/2 and HTTP/3 at an edge close to users (Azure Front Door or a CDN with points of presence in Sydney, Melbourne and Perth, or overseas for international users), keep warm pooled connections from the edge to the origin in Australia East, and cache what you can at the edge. Inside the data centre, connection reuse and fewer calls matter far more than the protocol version.

Option When it fits Cost When not to
HTTP/2 end to end gRPC, many parallel calls to one host Mostly config Proxies that don't support it
HTTP/3 at the edge/CDN Mobile, regional or overseas users, lossy networks UDP 443 open, more CPU (paid by the edge) Corporate networks that block UDP
HTTP/3 on Kestrel Direct client connections, no edge proxy libmsquic on Linux, ops work Behind an L7 proxy that terminates anyway
Stay on HTTP/1.1 In-region service calls with pooled connections None When you need gRPC or multiplexing

On security: QUIC can't be run without TLS 1.3 and encrypts most transport metadata, which is good for privacy but makes middlebox inspection and some network troubleshooting harder; 0-RTT resumption trades a round trip for replay risk, so servers should accept 0-RTT only for idempotent requests.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions status codes, methods or headers alongside versions Why: Checks their wider grasp of HTTP semantics and the practical differences between versions.
    How to answer

    HTTP is a request/response protocol: method + path + headers (+ body) in, status + headers (+ body) out.

    • Methods: GET/HEAD/OPTIONS are safe; GET, PUT, DELETE are idempotent (repeating has the same effect); POST and usually PATCH are not, so retries need an idempotency key.
    • Status codes: 2xx success, 3xx redirect/not modified, 4xx client error (400, 401 vs 403, 404, 409, 422, 429), 5xx server error (500, and 502/503/504 usually from proxies or gateways).
    • Headers: Content-Type, Accept, Authorization, Cache-Control, ETag/If-None-Match, Retry-After, traceparent.
    • Versions: HTTP/1.1 is text with one request at a time per connection; HTTP/2 is binary with multiplexed streams and header compression on one TCP connection; HTTP/3 does the same over QUIC/UDP, removing TCP head-of-line blocking.
  2. When: Candidate mentions QUIC or UDP Why: Checks they understand TCP vs UDP and why HTTP/3 chose UDP.
    How to answer
    • TCP is connection-oriented and gives a reliable, ordered byte stream: handshake, acknowledgements, retransmission, flow control and congestion control. Cost: a setup round trip and head-of-line blocking (one lost packet stalls everything behind it).
    • UDP sends independent datagrams with no connection, no ordering and no retransmission. It is lightweight and low-latency, and the application decides what to do about loss.

    Use TCP for most APIs, databases and file transfer. Use UDP for DNS, real-time media, games, metrics (StatsD) and as the base for QUIC. HTTP/3 runs on QUIC over UDP so it can combine TLS 1.3 with the transport handshake, avoid TCP's head-of-line blocking between streams, and survive network changes.

  3. When: Candidate mentions gRPC or long-lived HTTP/2 connections behind a load balancer Why: Checks they know why HTTP/2 traffic can pin to one pod with L4 load balancing.
    How to answer

    A load balancer spreads traffic across healthy instances.

    • Layer 4 (TCP/UDP: Azure Load Balancer, AWS NLB, Kubernetes Services via kube-proxy) picks a backend per connection using IPs and ports. Fast, protocol-agnostic, no HTTP awareness.
    • Layer 7 (HTTP: App Gateway, ALB, Front Door, ingress controllers, Envoy, YARP) picks per request, can route by path/host/header, terminate TLS, retry and add headers.

    Health checks remove unhealthy instances (in Kubernetes: readiness for traffic, liveness for restarts). Algorithms: round robin, least connections/requests, hashing. Sticky sessions pin a user to one instance, which hurts scaling and failover. Connection draining stops new traffic to an instance before shutdown so in-flight requests finish.

    gRPC uses long-lived HTTP/2 connections, so an L4 balancer balances connections, not calls: one client connection carries all its calls to one pod. Use L7 balancing (mesh/Envoy) or client-side load balancing.

🛠 Real-world problems: how you handle them

HTTP/2 enabled but tail latency on mobile got worse
Situation
A consumer API for a [retail] mobile app, served through [Azure Front Door] to App Service in Australia East. Users in [regional Western Australia] on 4G. The team enabled HTTP/2 end to end expecting a speed-up.
Signals
Median latency improved slightly, but app-reported p99 rose from 2.4 s to 3.8 s. Complaints came from users on weak signal. Server-side duration was unchanged.
Investigation
Split Real User Monitoring data by network type and region: the regression was confined to high-loss connections. Reproduced in a lab with `tc netem` (100 ms delay, 2% loss) and k6: one HTTP/2 connection suffered TCP head-of-line blocking where the old six HTTP/1.1 connections had spread the loss. Confirmed the app leg still ran HTTP/1.1 behind the edge, so Kestrel settings were irrelevant.
Resolution
Immediate: kept HTTP/2 at the edge (median gains were real) and enabled HTTP/3 at the edge so capable clients could use QUIC. Longer term: cut the home screen from 28 calls to 4 through an aggregate endpoint, which reduced exposure to loss regardless of protocol.
Prevention
Load tests with injected latency and loss in the pipeline before network changes; dashboards split by negotiated protocol and network type; an ADR stating protocol changes need client-side p95/p99 evidence.

How to tell it (STAR)

**S:** At [company], we switched our mobile API to HTTP/2 expecting faster screens, but users on weak connections in [regional areas] started reporting slower loads. **T:** I was asked to find out why and fix it without undoing the gains for everyone else. **A:** I split our client-side telemetry by network type and saw p99 had risen only on lossy connections. I reproduced it with netem and k6, and showed that one HTTP/2 connection stalled every request on a lost packet, while six HTTP/1.1 connections had spread that risk. We enabled HTTP/3 at the edge for capable clients and, more importantly, merged 28 home-screen calls into 4. **R:** p99 on poor connections dropped from 3.8 s to [1.9 s], the median kept its improvement, and protocol changes now need a loss-injected load test first.

↩ Usually asked after

More in API Performance

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me