APIs & Networking Deep Dive · 2 of 3

Networking Fundamentals — From URL to Response

Type a URL, hit enter. In about 200 milliseconds, your laptop finds an unrelated machine somewhere in the world, agrees on a shared encryption key with it, asks it a question, and renders the answer. Almost every layer of that trip is a place your app can break.

DNSTCPTLSHTTPOSICORS
← Back to APIs & Networking
The Trip

What Happens When You Hit Enter

The Six Steps

  • 1. DNS lookup. example.com93.184.216.34. Your OS asks a resolver, which asks the root, the TLD, then the authoritative server. Cached aggressively.
  • 2. TCP handshake. SYN → SYN-ACK → ACK. Both sides agree to talk. One round trip.
  • 3. TLS handshake. Certificate, key exchange, cipher selection. One more round trip (TLS 1.3) or two (TLS 1.2).
  • 4. HTTP request. GET /path HTTP/1.1 + headers + body.
  • 5. Server processes. Reverse proxy → load balancer → app → database → back.
  • 6. Response. Status line, headers, body. Connection stays open for the next request (keep-alive).
The Stack

OSI & TCP/IP Layers

LayerWhat It DoesYou'll See
ApplicationWhat humans care aboutHTTP, gRPC, WebSocket, DNS, SMTP, SSH
TransportReliable (or fast) delivery between programsTCP, UDP, QUIC
NetworkRouting packets between machines, anywhereIP (v4/v6), ICMP
LinkMoving frames over a single hop of cable/wifiEthernet, Wi-Fi, MAC addresses
PhysicalElectrons, light, radioCables, fibre, antennas

Most of your career will live in the top two layers. When something feels broken below them — packet loss, MTU issues, asymmetric routing — that's when you call the network team.

Drilldown

The Concepts You'll Hit Daily

DNS — The Internet's Phone Book

Hierarchical, cached, and slower than you think on a cold lookup. Records you'll touch: A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), TXT (verification, SPF/DKIM), NS (delegation).

The TTL is a contract. Set it short before a migration, long for stability. "DNS hasn't propagated yet" almost always means a cache somewhere is honoring an old TTL.

TCP vs UDP vs QUIC

TCP guarantees ordered, reliable bytes. Costs: handshake, retransmits, head-of-line blocking. The web rides on this.

UDP is fire-and-forget. No handshake, no retransmit. Used for DNS, video, games, VoIP — anywhere "stale" beats "late."

QUIC is UDP with the good parts of TCP rebuilt in user space — faster handshake, no head-of-line blocking, connection migration across networks. It's the foundation of HTTP/3.

TLS — Encryption and Identity

TLS does two jobs: encrypt the channel and authenticate the server (and optionally the client) via certificates signed by a CA. Your browser ships with a list of trusted CAs; the server presents a chain that ends at one.

Things to know: certs expire (set up auto-renewal — Let's Encrypt + cert-manager); SNI lets one IP host many domains; mTLS adds client certs for service-to-service trust; HSTS tells browsers to refuse HTTP for your domain forever.

HTTP/1.1 → HTTP/2 → HTTP/3
  • 1.1: text, one request at a time per connection. Browsers opened 6 connections in parallel to fake concurrency.
  • 2: binary frames, multiplexed streams over one TCP connection, header compression.
  • 3: same as 2 but on QUIC/UDP — kills head-of-line blocking at the transport layer, faster on flaky networks.
IP Addresses, Ports, NAT

IP identifies a machine; port identifies a program on it (80 = HTTP, 443 = HTTPS, 22 = SSH, 5432 = Postgres). IPv4 ran out of addresses years ago — IPv6 has 2¹²⁸ of them. NAT lets a whole home network share one public IPv4 by rewriting source addresses.

CORS — The Browser's Safety Belt

By default a page on a.com cannot read responses from b.com. The server at b.com opts in by sending Access-Control-Allow-Origin. For non-trivial requests the browser first sends an OPTIONS preflight asking permission.

CORS is enforced by the browser, not the server. curl ignores it entirely — that's why the same call works in your terminal and fails in your app.

Load Balancers & Reverse Proxies

A load balancer spreads traffic across many backend servers. L4 (TCP) ones route on IP/port; L7 (HTTP) ones route on path, header, cookie. Algorithms: round-robin, least-connections, IP hash for sticky sessions.

A reverse proxy (nginx, HAProxy, Envoy, Cloudflare, AWS ALB) sits in front of your app and does TLS termination, caching, rate-limiting, header rewrites, and load balancing. Almost every production app has one.

CDNs — Caches Near the User

Cloudflare, Fastly, CloudFront, Akamai. Hundreds of edge locations cache static assets and increasingly run code. Cache-Control headers tell the CDN how long to hold a response; cache keys decide what counts as "the same" request. Get the keys wrong and one user's data leaks to another.

Cookies, Sessions, & Same-Site

A cookie is just a header the browser echoes back. Flags that matter: Secure (HTTPS only), HttpOnly (no JS access), SameSite=Lax/Strict/None (cross-site behavior). Modern browsers default to Lax, which kills most CSRF — but you still need to think about it.

Toolbox

How Engineers Debug Networks

ToolWhat It's For
dig / nslookupInspect DNS records and resolver chain.
curl -vSee the full request, response headers, and status.
ping / tracerouteReachability and the path packets take.
openssl s_clientInspect a TLS handshake and certificate chain.
tcpdump / WiresharkPacket capture for the hard cases.
Browser DevTools → NetworkWaterfall, timing, headers, response. The first place to look on the client side.
Reality Check

Where Networks Bite

  • The network is not reliable. Packets drop, connections die, retries duplicate work. Build for it: timeouts, circuit breakers, idempotent operations.
  • Latency > bandwidth, usually. Twenty serial round-trips will dominate any payload size. Batch requests, pipeline, push instead of poll.
  • "It works on localhost" usually means TLS, CORS, DNS, or a corporate proxy is the difference.
  • Time isn't free. A new TLS connection across a continent costs ~150 ms — keep-alive and connection pooling are not optional at scale.
Continue

More on APIs & Networking