06. HTTP & the Network Path

Big picture: After DNS gives you an IP, the client still must open a connection, secure it, and speak HTTP before your API code runs. Most of a β€œslow request” is often network + TLS, not your database.

This lesson fills the gap between DNS and Load Balancing: what happens on the wire, how HTTP versions differ, and how to budget latency like an interviewer expects.

Prerequisites: 04. Clients, Servers & APIs, 05. How DNS Resolution Works
Read next: 07. Load Balancing β€” many connections land on one LB IP.


Learning goals

By the end of this lesson you will be able to:

  • Trace DNS β†’ TCP β†’ TLS β†’ HTTP β†’ response for a typical API call
  • Explain RTT and why geography matters
  • Describe TCP handshake and TLS handshake at a beginner level
  • Compare HTTP/1.1, HTTP/2, and HTTP/3 for system design
  • Use connection reuse (keep-alive) to cut latency
  • Build a rough latency budget (where time goes)
  • Place CDN / edge / TLS termination correctly in an HLD
  • Avoid confusing β€œapp slow” with β€œnetwork slow”

The full path of one HTTPS request

StageWhat it doesOften forgotten?
DNSName β†’ IPYes β€” see lesson 05
TCPReliable byte stream to the IP:portYes
TLSEncrypts the stream (HTTPS)Yes β€” expensive RTT
HTTPRequest / response semanticsNo β€” this is what APIs discuss
App + DBYour business logicWhere we spend most design time

Interview phrase: β€œUser-perceived latency is the sum of network round trips plus server time β€” not server time alone.”


RTT β€” the unit of network pain

RTT (Round-Trip Time) = time for a packet to go to the server and back.

Client β†’ serverTypical RTT (ballpark)
Same city / region5–20 ms
Cross-country40–80 ms
Intercontinental100–250+ ms

Why RTT matters

Many steps need at least one RTT:

  • TCP handshake β‰ˆ 1 RTT (classic)
  • TLS 1.2 handshake β‰ˆ 2 RTTs (often)
  • TLS 1.3 β‰ˆ 1 RTT (better)
  • Each HTTP/1.1 request on a new connection pays this again

Example: Mumbai user β†’ Virginia API, RTT β‰ˆ 180 ms.

TCP  1Γ—180 = 180 ms
TLS  2Γ—180 = 360 ms   (TLS 1.2 style)
HTTP request/response body travel β‰ˆ 180 ms
────────────────────────────────────
Network-ish floor β‰ˆ 720 ms
+ DNS (if cold) + server time

Your handler can be 20 ms and the user still waits ~1 second. That is why CDN, regional deploy, and connection reuse show up in designs.

Elevator analogy

Network ideaElevator
RTTTime to ride to the top floor and back
HandshakeCalling the elevator before you can load cargo
Keep-aliveKeeping the elevator at your floor for the next trip
CDNBuilding a second elevator shaft in your neighborhood

TCP β€” opening the pipe

TCP gives a reliable, ordered stream between client and server IP:port (e.g. 203.0.113.10:443).

Three-way handshake (simplified)

Client β†’ Server: SYN      ("want to connect")
Server β†’ Client: SYN-ACK  ("OK, me too")
Client β†’ Server: ACK      ("go")

Cost β‰ˆ 1 RTT before any HTTP bytes.

Beginner facts worth knowing

IdeaPlain meaning
Port 443Usual HTTPS
Port 80Usual HTTP (often redirects to HTTPS)
Loss / retransmitBad Wi-Fi β†’ TCP retries β†’ latency spikes
Connection = memoryEach open TCP conn costs RAM on LB/app β€” limits matter at huge fan-out

You do not need Congestion Window deep-dives in most interviews. You do need: β€œnew connection costs RTT(s).”


TLS β€” making the pipe private

HTTPS = HTTP over TLS (TLS replaced older β€œSSL” in practice).

What TLS buys you

PropertyMeaning
EncryptionEavesdroppers can’t read the JSON
IntegrityTampering is detectable
AuthenticationCertificate proves you’re talking to api.myapp.com (not an impostor)

Handshake cost (mental model)

TLS 1.2 (typical story): ~2 RTTs before application data
TLS 1.3:                 ~1 RTT  (session resumption can be 0-RTT in some cases)

Certificates are usually terminated at the load balancer or CDN (Load Balancing β€” SSL termination). App servers often see plain HTTP on a private network.

Certificate check failure

User sees browser warnings β€” not your 500 handler. DNS pointing to the wrong host + mismatched cert is a classic outage class.


HTTP β€” the language of APIs

Once the TLS pipe is up, the client speaks HTTP.

Request / response (reminder)

GET /api/v1/feed?cursor=abc HTTP/1.1
Host: api.myapp.com
Authorization: Bearer ...
Accept: application/json

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 1234

{"items":[...]}

API design (verbs, status codes, idempotency) lives in Lesson 04. Here we care about how versions share the connection.


HTTP/1.1 vs HTTP/2 vs HTTP/3

HTTP/1.1 β€” one request at a time per connection (classic)

  • Keep-alive reuses the TCP+TLS session for many requests (huge win vs new handshake each time).
  • Head-of-line blocking: one slow response delays the next request on that connection.
  • Browsers open ~6 parallel connections per host to fake concurrency.
Conn1: req1 .......... resp1 | req2 ..... resp2
         ↑ stuck waiting even if req2 is tiny

HTTP/2 β€” multiplex on one connection

  • Many request/response streams share one TCP+TLS connection.
  • Binary framing, header compression (HPACK).
  • Still suffers if TCP packet loss blocks the whole connection.

System design takeaway: Fewer connections to your LB, better parallel loading of APIs + assets on one host.

HTTP/3 β€” HTTP over QUIC (UDP)

  • Built on QUIC, not TCP.
  • Loss on one stream hurts less (no TCP HOL blocking at transport the same way).
  • Growing adoption via browsers/CDNs; apps often get it β€œfor free” at the edge.
VersionTransportMultiplexBeginner interview line
1.1TCPLimited (multi-conn)Keep-alive matters
2TCPYesOne conn, many streams
3QUIC/UDPYesBetter on lossy mobile nets

You rarely β€œpick HTTP/3 in LLD.” You recognize CDNs/LBs negotiate versions and that mobile + high RTT benefits most from H2/H3 + edge.


Keep-alive & connection reuse

Without reuse (worst case)

For every API call:
  DNS? + TCP + TLS + HTTP

Mobile apps that open a fresh TLS session per request feel terrible on high RTT.

With keep-alive / connection pool

Once:
  DNS + TCP + TLS
Then many:
  HTTP request / response on same connection
LayerReuse mechanism
BrowserPersistent connections, H2 multiplex
Mobile / backend HTTP clientConnection pool
LB β†’ appPooled upstream connections

Interview tip: When discussing chatty microservices, mention connection pooling and avoid chatty cross-region calls (each call Γ— RTT).


Latency budget β€” where does 800 ms go?

Worked example: user in Bangalore, API in us-east-1, cold connection, TLS 1.2-ish, simple read.

StepBudget (illustrative)
DNS (cold)30–80 ms
TCP handshake1 Γ— RTT β‰ˆ 180 ms
TLS handshake2 Γ— RTT β‰ˆ 360 ms
HTTP request + response flightβ‰ˆ 180 ms
LB + app + DB20–50 ms
Total~770–930 ms

Same app in Mumbai region (RTT 15 ms):

StepBudget
TCP + TLS 1.3~30 ms
Flight + server~40 ms
Total~70–100 ms

What this teaches for HLD

  1. Put static & cacheable content on a CDN near users.
  2. Deploy APIs regionally if audience is multi-continent.
  3. Reuse connections; avoid request waterfalls (A waits for B waits for C).
  4. Measure TTFB (time to first byte) separately from download time of large bodies.
  5. Optimizing SQL from 40 ms β†’ 5 ms does nothing visible if TLS+RTT dominate.

TTFB, download time, and large responses

MetricMeaning
TTFBTime until first response byte β€” handshake + queue + server think time
Content downloadRest of the body β€” depends on size / bandwidth
p99 latencyTail β€” often retries, GC, cold caches, network blips

A 2 MB JSON feed over a slow mobile link can dominate after TTFB. Prefer pagination, compression (gzip / br), and smaller payloads β€” API design meets network reality.


Where TLS and HTTP terminate in real architectures

PatternClient β†’ edgeEdge β†’ originNotes
TLS at CDNHTTPSOften HTTPS to originCommon for websites
TLS at LBHTTPSHTTP in VPCClassic app tier β€” Lesson 07
mTLS service meshβ€”Mutual TLS between servicesAdvanced microservice hardening

Beginners: terminate TLS at CDN or LB; don’t invent per-instance public certs unless you must.


Proxies you’ll hear mixed up

TermRole
Forward proxyClient-side middlebox (company egress)
Reverse proxySits in front of your servers (Nginx, Envoy, often the LB)
API gatewayReverse proxy + auth, rate limit, routing β€” Case 24
Load balancerDistributes across many backends β€” Lesson 07

Same box can wear multiple hats. In diagrams, label what problem it solves.


Mobile and flaky networks

RealityDesign implication
High RTT, packet lossPrefer H2/H3 via CDN; minimize round trips
App backgroundedTimeouts, retries with jitter β€” see 16. Retries & Resilience
Radio spin-upBatch requests; don’t chat every 100 ms
OfflineQueue writes locally; sync later

Chat and realtime (Case 07) use long-lived connections (WebSockets) so you don’t redo TLS constantly β€” different trade-offs (stateful gateways, sticky sessions).


Back-of-the-envelope: connection capacity

Rough intuition for interviews (order of magnitude):

Each idle TLS connection β‰ˆ few KB to tens of KB RAM on server/LB
100k concurrent connections β‰ˆ hundreds of MB to a few GB RAM
+ CPU for handshakes during thundering herd (sale start, outage recovery)

Thundering herd: millions of clients reconnect at once after a blip β†’ handshake CPU spike. Mitigate with staggered reconnect, connection reuse, edge termination.

Sale-night lesson (Case 44): CDN + warm connections matter as much as app count.


Check your understanding

  1. List the steps after a user taps β€œLoad feed” on HTTPS, starting from DNS.
  2. RTT is 100 ms. Roughly how much time for TCP + TLS 1.2 before HTTP?
  3. Why does HTTP/2 help a page that loads 30 small API resources?
  4. Your DB query dropped from 50 ms to 5 ms, but users in another continent still see ~800 ms. Why?
  5. Where should TLS usually terminate in a beginner HLD?
  6. What is keep-alive and why do mobile clients need connection pools?
Answers
  1. DNS β†’ TCP handshake β†’ TLS handshake β†’ HTTP request β†’ LB/app/DB β†’ HTTP response.
  2. TCP ~100 ms + TLS ~200 ms β‰ˆ 300 ms before HTTP data (classic 1+2 RTT model).
  3. Multiplexes many streams on one connection β€” avoids 30Γ— handshake or 6-conn limit waterfalls.
  4. Cross-continent RTT + TLS dominate; server time was never the bottleneck.
  5. CDN or load balancer (public edge), not every app VM.
  6. Reuses TCP/TLS so later requests skip handshakes; pools manage many parallel reusable conns.

Common beginner mistakes

MistakeBetter
Optimizing only SQL for β€œlatency”Budget DNS+TCP+TLS+RTT first
New TLS connection per API callKeep-alive / H2 / client pools
Drawing Client β†’ App with no DNS/LB/TLSShow edge termination
β€œHTTP/3 will fix my bad API chatty design”Reduce round trips and payload size
Ignoring geographyRegional deploy or CDN for static; measure RTT

Recap

  • User time = network round trips + server time; RTT is the currency.
  • Path: DNS β†’ TCP β†’ TLS β†’ HTTP β†’ app.
  • TLS handshakes are expensive; reuse connections; prefer TLS 1.3 / H2 at the edge.
  • HTTP/1.1 vs 2 vs 3 = how streams share connections, not different REST verbs.
  • Build a latency budget before blaming the database.
  • Terminate HTTPS at CDN/LB; pool connections; design for mobile RTT.

Next: Load Balancing β€” distributing many TCP/TLS sessions across healthy backends.

Previous: How DNS Resolution Works