Networking stack
A request crosses several layers, each adding latency and its own
failure modes. Debugging effectively means knowing which layer produced
a symptom: a name that did not resolve, a connection that never
established, or a response that arrived slowly.
Method
- Attribute latency by phase. Name resolution, connection
establishment, security handshake, request, and response each take
measurable time, and the slow one tells you where to look (see
dns-fundamentals, tls-and-certificates).
- Know that connection setup is expensive. Multiple round trips
before any data moves, which is why connection reuse and pooling
matter so much on high-latency links.
- Understand the round trip as the unit of cost. Bandwidth rarely
limits small requests; the number of sequential round trips does, and
it is bounded by physics.
- Distinguish the failure shapes. Connection refused, timeout, and
reset mean different things: nothing listening, no response, and
forcibly closed respectively.
- Expect middleboxes to interfere. Proxies, firewalls, and load
balancers terminate connections, buffer, and impose their own
timeouts, which is where mysterious behaviour usually originates.
- Set timeouts at every layer. Connect, read, and total, since a
missing timeout at one layer makes the others irrelevant (see
timeouts-and-retries).
- Test on realistic networks. Mobile and international links behave
nothing like a local one, and the differences are qualitative rather
than a slower version of the same thing.
Boundaries
The stack is deliberately abstracted, and most application code should
not care until it must. Encrypted transport limits what intermediate
inspection can tell you. Cloud networking adds virtual layers with their
own limits and failure modes (see cloud).
1---2name: networking-stack3description: Understand the layers between a request and its response, so latency, connection failures, and timeouts can be attributed to the right layer. Use when network behaviour is unexplained or performance varies by geography.4---56# Networking stack78A request crosses several layers, each adding latency and its own9failure modes. Debugging effectively means knowing which layer produced10a symptom: a name that did not resolve, a connection that never11established, or a response that arrived slowly.1213## Method14151. **Attribute latency by phase.** Name resolution, connection16 establishment, security handshake, request, and response each take17 measurable time, and the slow one tells you where to look (see18 dns-fundamentals, tls-and-certificates).192. **Know that connection setup is expensive.** Multiple round trips20 before any data moves, which is why connection reuse and pooling21 matter so much on high-latency links.223. **Understand the round trip as the unit of cost.** Bandwidth rarely23 limits small requests; the number of sequential round trips does, and24 it is bounded by physics.254. **Distinguish the failure shapes.** Connection refused, timeout, and26 reset mean different things: nothing listening, no response, and27 forcibly closed respectively.285. **Expect middleboxes to interfere.** Proxies, firewalls, and load29 balancers terminate connections, buffer, and impose their own30 timeouts, which is where mysterious behaviour usually originates.316. **Set timeouts at every layer.** Connect, read, and total, since a32 missing timeout at one layer makes the others irrelevant (see33 timeouts-and-retries).347. **Test on realistic networks.** Mobile and international links behave35 nothing like a local one, and the differences are qualitative rather36 than a slower version of the same thing.3738## Boundaries3940The stack is deliberately abstracted, and most application code should41not care until it must. Encrypted transport limits what intermediate42inspection can tell you. Cloud networking adds virtual layers with their43own limits and failure modes (see cloud).