Networking & Protocols
What happens between the client and your server, and the four ways to push data back the other way, with the cost of each at a million connections.
Prerequisites: You have typed a URL and seen a page.
After this: Choose a transport for realtime features and explain the connection cost of each.
Suggested first pass: Read sections 1–5, answer each section in your own words, then use the remaining failure modes and exercises as the advanced pass.
A browser asks for api.example.com/orders. Before any of your code runs, four things happen.
- 1DNS resolves the name. Cached in the browser, the OS, and the resolver for as long as the TTL says, which is why DNS changes take time and why DNS is a poor failover tool.
- 2TCP handshake. One round trip before any data moves.
- 3TLS handshake. Roughly another round trip on a modern version.
- 4HTTP finally carries the request. Total:
200–300 msbefore your handler starts.
That total is why connection reuse matters. Keep-alive and connection pools exist to pay setup once instead of per request, and dropping them is a common cause of unexplained latency after a refactor.
Light through fibre crosses an ocean in roughly 60–80 ms one way, so a round trip between continents is 150–200 ms. No optimisation changes it. If users are global and latency matters, the answer is to put something near them, a CDN, a read replica, a regional deployment, not to make the server faster.