STACK
Ch 02 · Networking Deep Dive
Chapter 02 · Wires & protocols

Networking — from Ethernet frames to HTTP/3 and gRPC

The network is what makes "the system" a system. This chapter is the deep map: OSI, IP, TCP/UDP, TLS, DNS, HTTP/1/2/3, QUIC, BGP, load balancers, sockets, WebRTC.

2.1 · OSI vs the real internet

OSI layerWhat it doesReal example
L7 ApplicationSemantic protocolHTTP, gRPC, SMTP, SSH, DNS
L6 PresentationEncodingTLS, gzip, JSON, protobuf
L5 SessionConversationsRPC, NetBIOS (rare today)
L4 TransportEnd-to-end channelTCP, UDP, QUIC
L3 NetworkRouting across networksIPv4, IPv6, ICMP
L2 Data linkFrames within a linkEthernet, Wi-Fi (802.11)
L1 PhysicalBits on a wire / radioCopper, fibre, RF

In practice, engineers think in four layers: Link · Internet · Transport · Application.

2.2 · IP, subnets, routing

  • IPv4: 32-bit; ~4.3B addresses; CIDR notation 192.168.1.0/24 = mask of 24 leading bits.
  • IPv6: 128-bit; vast space; written in hex with :: compression.
  • Private ranges (IPv4): 10/8, 172.16/12, 192.168/16, plus 169.254/16 link-local.
  • NAT: routers translate between private and public addresses. Most home + corporate networks.
  • VPC / subnet: cloud equivalent — a private network you own; subnets per AZ.
  • Routing table: longest-prefix match decides the next hop.

2.3 · TCP — anatomy

Client Server SYN (seq=x) SYN-ACK (seq=y, ack=x+1) ACK (ack=y+1) — established 3-way handshake
  • Reliable, ordered, byte-stream protocol.
  • Congestion control: CUBIC (default Linux), BBR (Google) — different curves.
  • Flow control: receive window prevents the sender from overwhelming the receiver.
  • TIME_WAIT: 2× MSL (~60s) after close; matters under high connection churn — tune SO_REUSEADDR / use connection pools.
  • Nagle's algorithm + delayed ACK can interact badly; TCP_NODELAY for latency-critical small writes.

2.4 · UDP & QUIC

  • UDP: no handshake, no ordering, no delivery guarantees. Tiny header. Used by DNS, NTP, video / VoIP, QUIC.
  • QUIC (RFC 9000): TLS 1.3 + multiplexed streams + connection migration, all over UDP. Underpins HTTP/3.
  • Why QUIC wins over TCP+TLS: 0-RTT handshakes, no head-of-line blocking across streams, survives IP changes.

2.5 · DNS

RecordWhat it is
A / AAAAHostname → IPv4 / IPv6.
CNAMEAlias to another name (no IP).
MXMail server for the domain.
TXTFree text — SPF, DKIM, domain verification.
SRVService location with port + priority.
NSAuthoritative name servers.
CAAWhich CA may issue certs for the domain.
SVCB / HTTPSModern; advertises alt-svc + HTTP/3 endpoints.

Resolvers cache; TTL controls propagation speed. DNS-over-HTTPS / DoT encrypt resolver traffic.

2.6 · TLS 1.3 — what's actually happening

  1. Client sends ClientHello with supported versions, ciphers, ALPN, extensions, key share.
  2. Server sends ServerHello + certificate + key share + Finished — all in one round trip.
  3. Client verifies cert chain against trust store, sends Finished.
  4. Application data flows encrypted with AEAD ciphers (AES-GCM, ChaCha20-Poly1305).
  • mTLS: server also requires client cert (used in service mesh).
  • SNI: client signals which hostname; allows multi-tenant TLS termination.
  • 0-RTT: send early data on resumed sessions; beware replay risk.
  • HSTS: HTTP header forcing TLS for future visits.
  • Post-quantum: hybrid Kyber+X25519 key exchange shipping in 2024–2026.

2.7 · HTTP/1.1

  • Text-based; one request per connection (or keep-alive serial pipelining — rarely safe).
  • Verbs, status codes, headers, chunked transfer encoding.
  • Head-of-line blocking: a slow response blocks the rest on the same connection.
  • Workaround: browsers open 6 parallel connections per origin.

2.8 · HTTP/2

  • Binary framing; multiplexed streams over one TCP connection.
  • HPACK header compression.
  • Server push (largely abandoned; replaced by 103 Early Hints).
  • Still suffers TCP-level head-of-line blocking — fixed in HTTP/3.

2.9 · HTTP/3 (over QUIC)

  • HTTP semantics unchanged; transport is QUIC over UDP.
  • No TCP-level HOL blocking; faster handshakes; connection migration across IPs.
  • Adopted by all major CDNs and browsers; enabled via Alt-Svc / HTTPS RR.
  • Cost: more CPU per connection; harder to debug than TCP.

2.10 · Load balancers & proxies

LayerWhat it doesExamples
L4Routes by TCP/UDP 5-tuple. Fast; no payload inspection.AWS NLB, HAProxy (TCP mode), F5.
L7Reads HTTP; routes by host, path, headers; SSL terminates.Nginx, Envoy, HAProxy, AWS ALB, Cloudflare.
Service mesh sidecarL7 proxy per pod; mTLS, retries, telemetry.Envoy in Istio / Linkerd.

Strategies: round-robin, least-connections, consistent hashing, weighted, IP hash, slow-start, outlier detection (eject 5xx-y instances).

2.11 · CDNs & anycast

  • CDN edges cache content near users; cache-control headers govern policy.
  • Anycast: one IP advertised from many locations; BGP routes the user to the nearest.
  • Edge compute: V8 isolates (Cloudflare Workers), Edge Functions (Vercel), Compute@Edge (Fastly).
  • Origin shielding to reduce origin load.

2.12 · WebSockets, SSE, WebRTC

ProtocolUse case
WebSocketBi-directional, low-latency, persistent over HTTP upgrade.
SSE (EventSource)Server → client only; survives proxies; built-in reconnect.
WebRTCPeer-to-peer media + data (ICE/STUN/TURN); video chat, low-latency gaming.
WebTransportQUIC-based, bi-directional streams + datagrams; replacing WS slowly.

2.13 · BGP & the public internet

  • The protocol by which Autonomous Systems exchange routes.
  • Path-vector; relies on policy + trust — historically vulnerable to hijacks.
  • RPKI + BGP-SEC add cryptographic verification.
  • When AWS / Cloudflare has a "global outage" it's almost always BGP, DNS, or TLS — in that order.

2.14 · Self-check

Q1 · HTTP/3 sits over which transport?
TCP
SCTP
QUIC (over UDP)
UDP directly