Lesson 01 of 13 · The big picture
One request, from browser to pod
Follow one HTTPS request from a browser to a pod and back, hop by hop: DNS, CDN and anycast, WAF and DDoS protection, cloud load balancer, API gateway, Kubernetes Service, service mesh and the application. What each hop adds, what it costs in latency, where TLS starts and ends, which headers record the journey, and why the gateway sits where it does.
One request, many hops
When someone opens https://api.example.com/orders/42, the request crosses several systems before your code runs. Each one exists for a reason, and each one can break, add latency or hide the real problem. Knowing the path is the first step to designing it and to debugging it.
Sending a parcel to a big company: the address book finds the building (DNS), the local post office takes it nearest to you (CDN), security scans it (WAF), the mail room spreads parcels over several desks (load balancer), the reception desk checks who it's from, whether they're allowed, and which department gets it (API gateway), and the internal mail carries it to the right desk (Kubernetes and the mesh).
Hop by hop
| # | Hop | Its job | Typical latency |
|---|---|---|---|
| 1 | DNS | Turn the name into an address; can return the nearest or a healthy region | 0 to 50 ms (cached: 0) |
| 2 | CDN / edge network | Nearest point of presence via anycast; caches static content; usually the first TLS termination | 5 to 30 ms to the PoP |
| 3 | WAF and DDoS protection | Block known attacks, bots and floods before they cost you anything | ~1 ms |
| 4 | Cloud load balancer | Stable address, spreads connections across gateway replicas, health checks | ~1 ms |
| 5 | API gateway | Match host and path to a route; authenticate; rate-limit; retry; time out; log | 1 to 5 ms |
| 6 | Service + kube-proxy / eBPF | Pick a healthy pod for the Service | < 1 ms |
| 7 | Service mesh sidecar (optional) | mTLS between services, retries, metrics | ~1 ms per hop |
| 8 | Application | The actual work, often calling other services and databases | the rest |
A typical public API spends most of its time in steps 2 (distance to the user) and 8 (your code and database). The middle hops are cheap, unless a retry, a timeout or a cold connection makes them expensive.
Where TLS starts and ends
browser ══TLS══► CDN ══TLS══► load balancer ──► gateway ══mTLS══► pods (mesh)
(1) (2) (3)
(1) public certificate for api.example.com, terminated at the edge
(2) re-encrypted to your origin: never send plain HTTP over the internet
(3) inside the cluster: plain HTTP, or mTLS from a service mesh
Every proxy that terminates TLS can read the request. That's useful (it can route by path and check tokens) and it's a trust decision: only your own proxies, and your CDN provider, should terminate it. See How a TLS handshake builds trust for the handshake itself.
Headers that record the journey
Each proxy opens a new connection, so the application sees the proxy's address, not the user's. The journey is recorded in headers:
X-Forwarded-For: 203.0.113.7, 198.51.100.20 client, then each proxy that forwarded it
X-Forwarded-Proto: https original scheme
X-Request-Id: 7f3a9c1e-... one ID for this request on every hop
traceparent: 00-4bf92f3577b34da6...-00f067aa0ba902b7-01 W3C trace context for distributed tracing
Only trust X-Forwarded-For entries added by your own proxies: anyone can send a fake one from the internet. Gateways can be configured with how many trusted hops to count from the right.
Why the gateway sits there
The gateway is the last point every external request passes through before it spreads out to many services. That makes it the right place for policy that should be identical for all APIs:
- routing by host, path, header or method;
- authentication (tokens, keys, client certificates);
- rate limits and quotas per user, tenant or plan;
- timeouts, retries, circuit breaking;
- access logs, metrics and the first trace span.
What it should not do: business logic, or anything only one service needs. A gateway full of special cases becomes a shared bottleneck that every team must queue to change.
Try it: trace a real request
- Run
curl -sv https://example.com -o /dev/nulland find in the output: the resolved IP, the TLS version, the certificate's issuer and the HTTP version. - Run
dig +short example.comtwice from different networks (for example, phone hotspot and home). Do you get the same address? - In a cluster with an ingress controller or gateway, deploy an echo server that prints request headers (lesson 4 uses one) and list every
X-header your request picked up on the way. - For your own product, draw the path for one request and write each hop's owner (which team or provider).
Going deeper
- Latency budget: set a target for the whole request (for example p99 under 300 ms), then give each hop a share. Timeouts and retries must fit inside it (lesson 7).
- Static stability: if the CDN or the global DNS fails, what still works? Many outages are at the edge, not in the clusters (lesson 10).
- Internal traffic (service to service) usually skips the edge and the gateway, and uses the mesh or plain Services; some platforms add an internal gateway for traffic between teams.
Recap
- A request crosses DNS, the edge (CDN, WAF, DDoS protection), a load balancer, the gateway, Kubernetes and maybe a mesh before it reaches the application.
- TLS is usually terminated at the edge, re-encrypted to the origin, and optionally mTLS inside.
X-Forwarded-For,X-Request-Idandtraceparentcarry the journey; trust them only from your own proxies.- The gateway is where policy common to all APIs belongs; business logic does not.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.