HTTP Semantics, HTTP/2 and HTTP/3: Methods, Caching and the Wire Protocols Underneath


System Design Phase 2: Networks, Performance & Failure
Core Lesson 5 of 86 17 min read Updated Nov 30, 2026

A mobile client times out on POST /orders after 10 seconds and retries. The first request had actually succeeded; it was just slow. The customer is charged twice. A week later, a different team adds Cache-Control: public, max-age=60 to a profile endpoint to cut load. For the next minute, the CDN serves one user’s profile, email address included, to everyone who asks for that URL.

Neither bug is exotic. Both come from treating HTTP as “a way to send JSON” instead of a protocol with precise semantics: which methods may be retried, who may cache a response, and for how long. Intermediaries such as CDNs, proxies, load balancers and client libraries act on those semantics automatically. If you send the wrong signals, they do the wrong thing at scale.

This article covers the semantics first, because they are the same in every HTTP version, then what HTTP/2 and HTTP/3 change underneath.

What HTTP is, in two layers

HTTP has two layers that are specified separately:

  • Semantics (RFC 9110, with caching in RFC 9111): methods, status codes, headers, caching rules, content negotiation. These mean the same thing in every version.
  • Wire format and transport: HTTP/1.1 (RFC 9112) is text over TCP. HTTP/2 (RFC 9113) is binary frames multiplexed over one TCP connection. HTTP/3 (RFC 9114) is binary frames over QUIC (RFC 9000), which runs over UDP.

A GET with If-None-Match and a 304 Not Modified reply behave identically whether they travel as text over HTTP/1.1 or as QPACK-compressed frames over HTTP/3. That separation is why you can upgrade the protocol without changing your API.

How it works: semantics

Methods, safety and idempotency

Two properties decide what clients and intermediaries may do on their own:

  • Safe: the method does not request a change of state on the server. Crawlers, prefetchers and caches may issue safe requests freely.
  • Idempotent: sending the same request N times has the same intended effect as sending it once. Clients and proxies may retry idempotent requests automatically after a network failure.
Method Safe Idempotent Typical use
GET, HEAD yes yes Read a resource
OPTIONS yes yes Discover capabilities, CORS preflight
PUT no yes Replace a resource at a known URL
DELETE no yes Remove a resource
POST no no Create, or run a non-idempotent action
PATCH no not by definition Partial update; idempotent only if you design it to be

Idempotency is about the effect, not the response. A second DELETE /items/42 may return 404 instead of 204, but the state is the same: item 42 is gone.

The order bug above happened because POST is not idempotent, so a blind retry is unsafe. The standard fix is an idempotency key: the client generates a unique key per logical operation and sends it in a header (Idempotency-Key is the common name, being standardised in an IETF draft), and the server stores the key with the result and returns the stored result on a repeat. The full pattern is in idempotency, and when and how to retry is in timeouts, retries and backoff.

Status codes that matter

Code Meaning Design note
200, 201, 204 OK, Created, No Content 201 should carry a Location header for the new resource
202 Accepted Work queued; return a URL to poll for status
301, 308 Permanent redirect 308 keeps the method and body; 301 may turn POST into GET
302, 307 Temporary redirect Same distinction: 307 preserves the method
304 Not Modified Response to a conditional GET; no body, saves bandwidth
400, 422 Bad request, unprocessable content Malformed versus well-formed but invalid
401, 403 Unauthenticated, forbidden 401 means “who are you”, 403 means “I know, and no”
404, 409, 412 Not found, conflict, precondition failed 412 is the answer to a failed If-Match
425 Too Early Server refuses to process a replayable 0-RTT request
429 Too Many Requests Send Retry-After; see rate limiting
500, 502, 503, 504 Server error, bad gateway, unavailable, gateway timeout 503 with Retry-After tells clients to back off

The split between 4xx and 5xx matters to machines: clients should not retry most 4xx responses (the request is wrong and will stay wrong), while 503 and 504 are often retryable with backoff. 429 is a 4xx that is retryable after the indicated delay.

Headers worth knowing

  • Host (or :authority in HTTP/2 and HTTP/3): which site the request is for. Lets one IP serve many domains.
  • Content-Type, Accept, Content-Encoding, Accept-Encoding: format and compression negotiation.
  • Authorization: credentials, usually a bearer token; covered in AuthN vs AuthZ.
  • Cache-Control, ETag, Last-Modified, Vary, Age: caching, below.
  • If-None-Match, If-Modified-Since, If-Match: conditional requests.
  • Retry-After: how long to wait before retrying a 429 or 503.
  • traceparent: the W3C Trace Context header that carries a distributed trace ID across services.
  • X-Forwarded-For or the standard Forwarded: the original client address when a proxy sits in front.

HTTP caching

Caching is the most valuable and most misused part of HTTP. The Cache-Control response header tells every cache on the path (browser, CDN, reverse proxy) what it may do:

  • max-age=N: the response is fresh for N seconds in any cache.
  • s-maxage=N: overrides max-age for shared caches such as CDNs.
  • public / private: private means only the end user’s browser may store it, never a shared cache. Personalised responses must be private (or no-store).
  • no-cache: may be stored, but must be revalidated with the origin before every use. It does not mean “do not cache”.
  • no-store: must not be stored anywhere. Use for sensitive data.
  • immutable: the content at this URL will never change. Pair with fingerprinted asset URLs such as app.3f9a2c.js.
  • stale-while-revalidate=N: after the response goes stale, a cache may serve it for up to N more seconds while it fetches a fresh copy in the background. Users get cache-hit latency; the origin gets one refresh instead of a burst.
  • stale-if-error=N: a cache may serve a stale copy for up to N seconds if the origin is failing. A cheap availability win.

Validators and conditional requests. An ETag is an opaque version identifier for a response body. When a cached copy goes stale, the cache sends If-None-Match: "v42". If the resource has not changed, the origin replies 304 Not Modified with no body, and the cache marks its copy fresh again. Last-Modified and If-Modified-Since do the same with timestamps, at one-second granularity. If-Match works the other way for writes: “update only if the current version is still v42”, which gives optimistic concurrency control and returns 412 on conflict.

Vary. If the response depends on a request header, say so: Vary: Accept-Encoding makes caches store gzip and Brotli variants separately. Varying on high-cardinality headers such as Cookie effectively disables shared caching. Edge caching strategy in depth is in CDN and edge caching.

sequenceDiagram
participant C as Client
participant K as CDN cache
participant O as Origin
C->>K: GET /config
K->>O: GET /config
O-->>K: 200, ETag v42, max-age 60, stale-while-revalidate 300
K-->>C: 200 from origin
Note over K: 60 s later the copy is stale
C->>K: GET /config
K-->>C: 200 stale copy served at once
K->>O: GET /config, If-None-Match v42
O-->>K: 304 Not Modified, no body
Note over K: copy fresh again for 60 s

Cookies

A cookie is a header-based state mechanism: the server sends Set-Cookie, the browser sends Cookie back on matching requests. The attributes are where security lives:

  • Secure: only sent over HTTPS.
  • HttpOnly: not readable from JavaScript, which limits damage from cross-site scripting.
  • SameSite=Lax|Strict|None: controls whether the cookie is sent on cross-site requests. Lax (the default in Chromium-based browsers when the attribute is missing) blocks it on cross-site subrequests and POSTs, which stops most cross-site request forgery. None requires Secure.
  • Domain, Path, Max-Age or Expires: scope and lifetime. The __Host- name prefix forces Secure, Path=/ and no Domain, pinning the cookie to one exact host.

Do not design around third-party cookies: Safari blocks them by default and Firefox partitions them per site. Session design is covered in AuthN vs AuthZ.

CORS

Browsers enforce the same-origin policy: a script from https://app.example.com cannot read responses from https://api.example.com unless that API opts in with Cross-Origin Resource Sharing headers.

  • For “simple” requests (GET, HEAD or POST with basic content types and no custom headers), the browser sends the request and only exposes the response if it carries a matching Access-Control-Allow-Origin.
  • For anything else (PUT, DELETE, JSON bodies, an Authorization header), the browser first sends a preflight OPTIONS request. The server answers with Access-Control-Allow-Origin, -Methods and -Headers. Access-Control-Max-Age lets the browser cache the preflight, which saves a round trip per request.
  • With credentials (cookies), Access-Control-Allow-Origin must name the exact origin, never *, and Access-Control-Allow-Credentials: true must be set.

CORS is a browser rule that relaxes the same-origin policy. It is not server-side access control: curl and other servers ignore it entirely. Authenticate and authorise every request anyway.

How it works: the versions

Connection reuse and HTTP/1.1

HTTP/1.1 keeps connections open by default (persistent connections), so the TCP and TLS setup cost is paid once and amortised over many requests. But each connection carries one request at a time: a slow response blocks everything queued behind it on that connection, which is HTTP-level head-of-line blocking. Pipelining was specified but never worked reliably in practice. Browsers work around it by opening up to 6 connections per host, and sites used to work around that by sharding assets across hostnames and bundling files.

HTTP/2

HTTP/2 keeps the semantics and replaces the wire format:

  • Binary framing and multiplexing: many concurrent streams share one TCP connection, interleaved as frames. A slow response no longer blocks others at the HTTP layer.
  • HPACK header compression: repeated headers such as cookies and user agents are sent as small table references.
  • Flow control and prioritisation per stream.
  • Server push was removed in practice. It was in the spec, but it rarely helped and often wasted bandwidth. Chrome disabled it by default in 2022, and it is effectively unused on the web today. Its replacement is 103 Early Hints plus Link: rel=preload, which tells the browser what to fetch without pushing bytes it may already have cached.

What HTTP/2 cannot fix is TCP-level head-of-line blocking. TCP delivers one ordered byte stream. If one packet is lost, every stream on the connection waits for the retransmission, even streams whose data arrived intact. On a lossy mobile network, one HTTP/2 connection can perform worse than six HTTP/1.1 connections.

HTTP/3 and QUIC

HTTP/3 runs over QUIC, a transport built on UDP that moves reliability, ordering and congestion control into the protocol itself:

  • Per-stream loss recovery: streams are independent at the transport layer, so a lost packet stalls only the stream it belongs to.
  • TLS 1.3 built in: QUIC integrates the TLS 1.3 handshake into its own, so transport and encryption are set up in one round trip instead of two. QUIC is always encrypted, including most of its transport headers.
  • 0-RTT resumption: a client that has talked to the server before can send a request in its very first flight. The handshake still happens; the early data just rides along with it, encrypted with keys from the previous session. Early data can be replayed by an attacker, so servers should accept it only for safe, idempotent requests, and can reject it or answer 425 Too Early.
  • Connection migration: connections are identified by connection IDs rather than by the IP and port 4-tuple, so a phone moving from Wi-Fi to cellular keeps its connection.
  • QPACK header compression, redesigned so that out-of-order delivery does not block header decoding.
sequenceDiagram
participant C as Client
participant S as Server
Note over C,S: HTTP/2 over TCP plus TLS 1.3, new connection
C->>S: TCP SYN
S-->>C: SYN-ACK
C->>S: ACK plus TLS ClientHello with key share
S-->>C: ServerHello, certificate, Finished
C->>S: Finished plus HTTP request
S-->>C: HTTP response
Note over C,S: HTTP/3 over QUIC, new connection
C->>S: QUIC Initial with TLS ClientHello
S-->>C: ServerHello, certificate, Finished
C->>S: Finished plus HTTP request
S-->>C: HTTP response

Adoption in 2026

HTTP/3 is supported by all major browsers and by the major CDNs and edge platforms, and servers and proxies such as nginx, Caddy, HAProxy and Envoy can serve it. Cloudflare’s published data has put HTTP/3 at roughly a quarter to a third of the requests it serves over the last few years, with HTTP/2 still the most common. Clients discover HTTP/3 through an Alt-Svc response header or an HTTPS DNS record (RFC 9460), and fall back to HTTP/2 over TCP when UDP is blocked, which still happens on some corporate and public networks. Inside data centres, service-to-service traffic is mostly HTTP/2 (gRPC is built on it) or HTTP/1.1, because the networks are low-loss and the benefits of QUIC are smaller.

HTTP/1.1 HTTP/2 HTTP/3
Transport TCP TCP QUIC over UDP
Requests per connection one at a time many, multiplexed many, multiplexed
Head-of-line blocking HTTP and TCP level TCP level only per stream only
New connection setup with TLS 1.3 2 RTT 2 RTT 1 RTT, 0-RTT on resumption
Survives IP change no no yes, connection migration

Where it breaks

Retrying non-idempotent requests. Libraries and proxies that retry POSTs on timeout create duplicates. Retry only idempotent methods, or POSTs carrying an idempotency key.

Caching personalised responses in shared caches. public on a response that varies by user leaks data. Default dynamic API responses to private or no-store, and opt specific public resources into shared caching.

Misreading no-cache. no-cache means “revalidate before use”, not “never store”. Use no-store for secrets.

Accepting 0-RTT for writes. Early data can be replayed. Only allow it for safe requests, or have the edge reject early data on anything else.

Long-lived HTTP/2 connections and load balancing. With one multiplexed connection per client, a layer 4 load balancer balances connections, not requests. A few busy clients can pin most traffic to a few backends. gRPC deployments typically need a layer 7 balancer or client-side balancing; see load balancing.

Protocol-level abuse. Multiplexing creates new attack surface. The HTTP/2 Rapid Reset attack disclosed in 2023 opened and immediately cancelled streams at huge rates to exhaust servers, and servers had to add per-connection limits on stream resets.

Assuming UDP works everywhere. Always keep an HTTP/2 fallback path for HTTP/3.

Real-world systems

  • Browsers negotiate HTTP/2 via TLS ALPN and learn about HTTP/3 via Alt-Svc or HTTPS DNS records, then race or cache the choice.
  • CDNs terminate HTTP/2 and HTTP/3 from users and talk to origins over pooled, long-lived connections, so the origin rarely sees handshakes at all.
  • gRPC uses HTTP/2 streams for unary and streaming RPCs, with trailers carrying the status; compared in REST vs GraphQL vs gRPC.
  • Payment APIs commonly require an idempotency key header on POST requests that create charges, precisely because clients retry on timeout.

How to apply it

  • Use the method that matches the effect. Make PUT and DELETE truly idempotent, and require idempotency keys on retryable POSTs.
  • Return precise status codes, and Retry-After on 429 and 503.
  • Set Cache-Control explicitly on every response. Defaults: fingerprinted static assets public, max-age=31536000, immutable; shared read-mostly API data public, max-age short plus stale-while-revalidate and an ETag; personalised data private; secrets no-store.
  • Reuse connections everywhere and pool them between services.
  • Enable HTTP/2 everywhere and HTTP/3 at the edge for user traffic, with fallback.
  • Cookies: Secure, HttpOnly, SameSite=Lax or stricter, __Host- prefix for session cookies.
  • CORS: allowlist exact origins, cache preflights, never treat CORS as authorisation.

Interview angle

Interview questions

Q1: Why does HTTP/2 not fully solve head-of-line blocking, and how does HTTP/3 fix it?

HTTP/2 removes HTTP-level blocking by multiplexing many streams over one connection, but that connection is a single TCP byte stream. When a packet is lost, TCP holds back all later bytes until the retransmission arrives, so every stream stalls, including those whose data arrived. HTTP/3 runs over QUIC, which tracks ordering and loss per stream, so a lost packet only delays the stream it carried. QUIC also merges the transport and TLS 1.3 handshakes into one round trip.

Q2: What does 0-RTT in TLS 1.3 and QUIC actually do, and what is the risk?

On resumption, the client uses a pre-shared key from an earlier session to encrypt application data and sends it alongside its ClientHello, so the server can process a request without waiting a round trip. The handshake still completes in parallel; 0-RTT does not skip it. The risk is replay: an attacker who captures the first flight can resend it, and the early data does not have the same replay protection as data sent after the handshake. So servers should only accept early data for safe, idempotent requests, can reject it, and can answer 425 Too Early to make the client resend after the handshake.

Q3: A CDN is serving one user’s data to another. What went wrong and how do you fix it?

The origin marked a personalised response as cacheable by shared caches, typically with public or with a max-age and no private, and the CDN keyed the cache on the URL alone. Fix it immediately by purging the CDN and setting Cache-Control: private or no-store on personalised endpoints. Longer term, default all dynamic responses to private, only opt specific public resources into shared caching, make sure the CDN does not cache responses that carry Set-Cookie or Authorization-dependent content, and add a test that checks caching headers on sensitive endpoints.

✅ Key takeaways

  • HTTP semantics (methods, status codes, caching) are the same in every version; HTTP/1.1, HTTP/2 and HTTP/3 only change the wire format and transport.
  • Safe and idempotent methods may be retried automatically; POST may not, so use idempotency keys.
  • Set Cache-Control on every response: private for personalised data, no-store for secrets, max-age plus stale-while-revalidate and ETags for shared read-mostly data.
  • HTTP/2 multiplexes streams but still suffers TCP head-of-line blocking; server push is effectively gone, replaced by 103 Early Hints.
  • HTTP/3 over QUIC gives per-stream loss recovery, a 1-RTT handshake, 0-RTT resumption for idempotent requests and connection migration, with HTTP/2 as the fallback.
  • CORS is a browser relaxation of the same-origin policy, not access control.

🧠 Check your understanding

0 / 4
  1. 1Which method can a proxy safely retry automatically after a connection drops, without an idempotency key?

  2. 2What does Cache-Control: no-cache mean?

  3. 3Why can one HTTP/2 connection perform worse than several HTTP/1.1 connections on a lossy network?

  4. 4A client resumes an HTTP/3 connection with 0-RTT and sends a POST that charges a card. What should the server do?

Where to go next

Finished this lesson?

Mark it complete to track your progress across the roadmap.