Skip to content
BIASED

Networking for services

The path of a request through DNS, TLS, proxies and load balancers: names and caches, the handshake, L4/L7, health checks, latency budgets and the fan-out tail.

A name as indirection

A user request rarely hits your process first. It crosses DNS, TLS terminators, load balancers, service meshes, sidecars and finally a Pod IP that did not exist an hour ago. Key idea: each hop is indirection — the client knows a name; behind the name, machines, versions and addresses can change, and each layer can health-check the next. The price is round trips, queues and caches that can be stale. Designing services means budgeting those costs and deciding where failure is detected.

Without indirection every client hard-codes IPs and every deploy is a coordinated edit. With too much indirection a 50 ms handler becomes a 200 ms client experience and nobody knows which hop owns the gap.

DNS and TLS

DNS maps names to addresses with TTLs. Short TTLs (20–60 s) fail over faster after a record change and load resolvers more; long TTLs (300–3600 s) hide changes and leave clients aimed at drained balancers. After resolve, a cold HTTPS client pays TCP then TLS before the first HTTP byte — often one–two RTTs for TLS 1.3, more for older stacks. Proxies and clients with pooled connections amortize handshakes toward backends; connection churn under load shows up as CPU on the terminator and as latency cliffs when pools thrash.

Toy budget on a measured path: TDNS=5T_{\mathrm{DNS}}=5 ms, RTT=40\mathrm{RTT}=40 ms (standing in for connect+TLS on a warm-ish path simplification), Tproxy=1T_{\mathrm{proxy}}=1 ms, Tbackend=60T_{\mathrm{backend}}=60 ms → 106 ms end-to-end if those pieces add on the path you measure. Real budgets allocate percentiles per hop and leave margin; means lie about the tail.

HTTP/2 and HTTP/3 multiplex streams on one connection — great until head-of-line issues or a single stuck connection strand many requests. Know which protocol your balancer speaks to clients vs to backends.

Load balancing and health checks

L4 balancers spread TCP connections cheaply — they see bytes and 5-tuples, not URLs. L7 balancers terminate TLS, parse HTTP, route by host/path, retry idempotent requests and measure per-request metrics — costing CPU and holding certificates. APIs almost always want L7 at the edge; pure TCP services may not.

Active health checks probe on a schedule: e.g. GET /healthz every 5 s, timeout 2 s, fall 3 failures → up to about 17 s (3×5+23\times5+2 style bound) to mark a backend down. At 50 RPS to that backend, up to ~850 failed requests can land before removal if nothing else intervenes. Passive checks eject after consecutive errors on real traffic (e.g. 5 errors) — at 50 RPS that can be ~0.1 s. Use both; drain (connection draining / preStop sleep / remove from target group before SIGTERM) so in-flight requests finish. A rolling deploy without drain is a self-inflicted packet loss event every release.

Health endpoints should verify critical dependencies shallowly or report degraded status without false-green. A /healthz that only checks process liveness will keep a Pod in rotation while its database credentials are wrong.

Fan-out and the tail

Latency budgets divide an SLO among hops; percentiles do not add — the p99 of a sum is not the sum of p99s. Measure the total path. Fan-out makes tails worse: if one request waits for NN independent backends each timely with probability 0.99, all are timely with 0.99N0.99^N — 0.904 for N=10N=10, about 0.366 for N=100N=100. Rare slowness on one machine becomes common for the calling request (Dean & Barroso, "The Tail at Scale"). Hedged requests, early cancellation, and deadlines fight that physics; unbounded fan-out without budgets invites SLO burns on "healthy" dependencies.

Retries at L7 interact with fan-out: retrying a fan-out call multiplies load on every dependency. Bound retries and prefer idempotent reads for automatic retry.

What changed

Hard-coded IPs Named service path
Change backends edit every client change DNS/balancer targets
Failure clients keep hitting the dead health checks + drain + retries elsewhere
Cost few RTTs DNS/TLS/proxy RTTs + cache risk
Tail risk local fan-out and layered retries

Service discovery inside a cluster (DNS to ClusterIP, or a mesh with endpoint subsets) refreshes faster than public DNS, but clients still cache. Readiness that flips false must be long enough for clients and balancers to notice — shorter than your deploy step's wait and longer than a single blip. Sticky sessions at L7 solve rare needs and create unbalanced replicas; prefer stateless handlers and external session stores.

Egress controls and private link patterns keep data-plane traffic off the public internet when talking to managed databases. Combine with the VPC design from cloud building blocks: private subnets, tightly scoped security groups or NetworkPolicies, and explicit allow paths you can name in an incident.

Next: Infrastructure as code — declaring the machines, balancers and DNS records themselves in Git so the path above is reproducible.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.