Notes
By hand
HTTP one point one is plain text, so we typed it with netcat. The request line: method GET, path /api /health, version. Then headers: Host, which lets one server host many sites, and Connection close. A blank line ends the headers. ShopRung answered with a status line, 200 OK, headers for the content type and length, a blank line and the JSON body, fifty bytes: status UP. Every HTTP library is building and parsing exactly this.
GET /api/health HTTP/1.1
Host: shoprung.test
Connection: close
HTTP/1.1 200 OK
Content-Type: application/
json; charset=utf-8
Content-Length: 50
{"status":"UP","app":
"ShopRung",...} Status codes
Status codes group by first digit. Two hundreds mean success. Three hundreds redirect: 301 permanent, three oh four means use your cached copy. Four hundreds blame the client: four oh one is not authenticated, four oh three is not allowed, four two nine is rate limited. Five hundreds blame the server. For operators, five oh two, five oh three and five oh four are the important ones: a proxy could not reach, found no healthy, or timed out waiting for the app behind it.
- 2xx ok: 200, 201, 204
- 3xx go elsewhere: 301, 302, 304 not modified
- 4xx client problem: 400, 401 who are you, 403 no, 404, 429 slow down 5xx server problem: 500, 502 bad gateway, 503 unavailable, 504 timeout
Keep-alive
HTTP one point one made connections persistent by default: keep alive. We measured fifty requests opening a new connection each time versus reusing one. Over plain HTTP, the new connection version cost about point three milliseconds a request, reused about point one to point two. Over HTTPS through nginx, a new connection cost 1.3 to one point eight milliseconds, reused under point four. That is on localhost; across a real network each handshake adds full round trips.
new reused
HTTP :8080 0.28-0.30
0.12-0.22
HTTPS :8443 1.33-1.82
0.26-0.35
localhost, 3 runs each
real networks add a round
trip per handshake HTTP/2
HTTP one point one has a limit: one request at a time per connection, so browsers opened about six connections per site. HTTP two keeps the same methods, headers and status codes, but sends them as binary frames, and multiplexes many requests as independent streams on one connection. Headers are compressed. gRPC, common between microservices, is built on HTTP two. But it still runs on TCP, so one lost packet holds up every stream behind it.
- HTTP/1.1: one request at a time per connection → browsers opened 6
- HTTP/2: binary frames, many streams at once on ONE connection
- header compression (HPACK)
- gRPC is built on HTTP/2
- still TCP underneath
Negotiation
How do client and server agree on HTTP two? During the TLS handshake, using an extension called ALPN. Our curl offered h two and HTTP one point one, and nginx accepted h two. On nginx one point twenty four that took one word in the listen line; newer versions use a separate http two on directive, which our older nginx rejected as an unknown directive, a real config migration gotcha.
ALPN: curl offers h2, http/1.1 SSL connection using TLSv1.3 ALPN: server accepted h2 using HTTP/2 nginx: listen 8443 ssl http2 (nginx 1.25+: http2 on;)
HTTP/3
HTTP three replaces TCP with QUIC, which runs over UDP port 443. QUIC includes TLS 1.3, so a secure connection is set up in one round trip, or zero when resuming. Loss on one stream does not block the others. Connections survive a change of IP address, like walking from Wi-Fi to mobile data. For operators: firewalls and load balancers must allow UDP 443. Our nginx build had no HTTP three module at all, so check your build.
- QUIC transport on UDP 443
- TLS 1.3 built in: setup in one round trip (or zero on resume)
- lost packet blocks only its own stream
- survives IP change (Wi-Fi to mobile)
- needs UDP 443 open
Time a request
When a request is slow, curl minus w splits it into phases. Our HTTPS request: name lookup in microseconds, TCP connect at seventy eight microseconds, TLS done at two and a half milliseconds, first byte at three point four, total three point four. The values are cumulative. Slow DNS points at the resolver, slow connect at the network, slow TLS at handshakes or certificates, and slow time to first byte at the application.
dns 0.000009 s connect 0.000078 s tls 0.002463 s ttfb 0.003386 s total 0.003416 s each value is cumulative slow dns/connect/tls/ttfb each points somewhere else
Common mistakes
Mistakes. No keep alive between a proxy and the application, so every request pays a new handshake. Treating all five hundreds alike, when five oh two, five oh three and five oh four each point somewhere different. Retrying POST requests that are not safe to repeat. Blocking UDP 443 and then wondering why HTTP three never activates. And health checks that omit the Host header and hit the wrong virtual host.
- no keep-alive between proxy and app
- treating every 5xx the same
- retrying non-idempotent POSTs blindly
- blocking UDP 443, then wondering about HTTP/3
- missing Host header in health checks
Say it like this
In the interview: HTTP one point one is text with persistent connections but one request at a time per connection. HTTP two is binary and multiplexes many streams over one TCP connection, negotiated with ALPN, but TCP loss still blocks all streams. HTTP three runs over QUIC on UDP with TLS 1.3 built in, so setup is faster and loss only affects one stream.
- "1.1 is text with keep-alive but one request at a time per connection. 2 is binary and multiplexes streams on one TCP
- connection, chosen by ALPN. 3
- runs on QUIC over UDP with TLS
- built in, so loss only blocks
- its own stream."