interviewpath
  • 0day streak
  • 10total XP
  • Level 1
0/5

Unit 4 · Networks · Lesson 5 of 10

Proxies, load balancing and CDNs

Between a client and a service sit reverse proxies, L4 and L7 load balancers and often a CDN. Knowing what each layer can see and decide (addresses and ports versus HTTP requests), how it spreads load, keeps connections and detects failure is central to backend and infrastructure system design.
About 3 h 30 minFocus mode

Step 1: Learn the ideas

  • Forward and reverse proxies
  • L4 (connection) versus L7 (request) load balancing
  • TLS termination and re-encryption
  • Balancing algorithms: round robin, least requests, power of two choices
  • Consistent hashing and Maglev-style lookup tables
  • Health checks, outlier detection and connection draining
  • Retries, timeouts and budgets across proxy layers
  • DNS-based and anycast global load balancing
  • CDNs, cache keys and HTTP caching headers
  • Preserving client identity (X-Forwarded-For, PROXY protocol)

Why it matters

It is easy to say "put a load balancer in front" in a design discussion. Good answers say which kind, where TLS terminates, how a backend is chosen, how failure is detected and what happens to long-lived connections during a deploy. Many incidents come from exactly these details: uneven load from connection-level balancing of HTTP/2 or gRPC, health checks that pass while the service is broken, retries multiplied by every proxy layer, or a CDN cache serving stale or private data.

Core ideas

Forward versus reverse proxy. A forward proxy acts for clients (corporate egress, filtering, caching). A reverse proxy acts for servers: it terminates client connections and opens its own connections to backends, which lets it terminate TLS, route by host or path, add headers, buffer slow clients, enforce limits and cache responses.

L4 versus L7. An L4 load balancer works with transport information: it chooses a backend per connection (or per UDP flow) from the five-tuple and forwards packets, sometimes without terminating TCP at all. It is fast and protocol-agnostic but cannot see requests, so one long-lived HTTP/2 or gRPC connection carrying thousands of requests lands on a single backend. An L7 load balancer terminates the connection, parses HTTP and balances each request; it can route by path or header, retry and observe status codes and latency, at the cost of more CPU and of becoming part of the protocol (timeouts, header limits, version translation). Large deployments layer them: DNS or anycast spreads clients across sites, L4 spreads connections across a fleet of L7 proxies, and L7 spreads requests across services.

Choosing a backend. Round robin ignores load. Least-outstanding-requests and "power of two random choices" (pick two at random, use the less loaded one) adapt cheaply to slow backends; weighted variants handle mixed capacity. Hashing keeps a client or key on the same backend for cache locality; consistent hashing and Maglev-style lookup tables remap only a small fraction of keys when backends change, and let a fleet of stateless L4 balancers agree on where a connection belongs.

Health and failure. Active health checks probe an endpoint; passive checks (outlier detection) eject backends that return errors or time out. A check that only confirms "process alive" misses broken dependencies, while one that tests every dependency can eject the whole fleet when a shared dependency blips, so cap the fraction that may be ejected. Connection draining lets in-flight requests finish before a backend leaves. Retries at several layers multiply load; retry budgets and deadlines keep them bounded.

CDNs. A CDN is a geographically distributed set of reverse proxies that cache content near users, terminate TLS close to them (saving handshake round trips) and keep warm connections back to the origin. Clients reach an edge through DNS or anycast. HTTP caching headers (Cache-Control, Vary, validators such as ETag) decide what may be stored; cache keys and invalidation are where mistakes leak private data or serve stale content.

Common misconceptions

  • "An L4 balancer spreads requests evenly." It spreads connections; with long-lived multiplexed connections the request load can be badly skewed.
  • "Round robin is good enough." With uneven request costs or a slow backend, load-aware choices noticeably reduce tail latency.
  • "Health checks make failover automatic and safe." Shallow checks miss real failures and deep checks can eject everything at once; design for both.
  • "A CDN only helps static files." Terminating TLS near users and reusing origin connections also speeds up uncacheable requests.
  • "The proxy is transparent." Every proxy adds timeouts, buffering, size limits and its own retry policy, and hides the client address unless it forwards it (X-Forwarded-For, PROXY protocol).

How to approach it

For any design, list the layers in order (DNS or anycast, L4, L7, service) and what each decides. Practice explaining connection versus request balancing with a gRPC example, and how consistent hashing limits remapping. Senior-level discussions add deploy safety (draining, slow start for new backends), failure domains, overload behavior and the interaction of retries across layers.

Suggested order

  1. 1Read the Google SRE book Ch. 19 (Load Balancing at the Frontend) for DNS-based balancing and balancing at the virtual IP address, then Ch. 20 (Load Balancing in the Datacenter) for subsetting, backend health and selection policies.
  2. 2Read the Envoy load-balancing overview and summarize in a table when round robin, least request, ring hash and Maglev fit.
  3. 3Read the Maglev paper sections on consistent hashing and connection tracking to see how an L4 balancer fleet survives membership changes.
  4. 4Read Computer Networks: A Systems Approach Section 9.4 (Overlay Networks) on content distribution networks.
  5. 5Put two backends behind a local reverse proxy and compare per-connection and per-request balancing with an HTTP/2 client; stop a backend mid-test and observe health checks and retries.

Step 2: Check off what you can do

Tap each one you can genuinely do or explain. Each earns 10 XP.

Step 3: Go deeper

  • Site Reliability Engineering (Google SRE book)Start here

    Google (free online edition)

    Section: Ch. 19: Load Balancing at the Frontend

    DNS-based traffic distribution and its limits, then network load balancing at a virtual IP with consistent hashing and connection tracking.

    Open(opens in a new tab)Link responded, 5 Oct 2026
  • Site Reliability Engineering (Google SRE book)Start here

    Google (free online edition)

    Section: Ch. 20: Load Balancing in the Datacenter

    Backend selection, subsetting, health states and avoiding overload of slow backends.

    Open(opens in a new tab)Link responded, 5 Oct 2026
  • Envoy documentation: load balancing overview

    Envoy Proxy project

    Reference for L7 balancing policies, health checking and outlier detection.

    Open(opens in a new tab)Link responded, 5 Oct 2026
  • Maglev: A Fast and Reliable Software Network Load Balancer

    USENIX

    Design of a software L4 balancer: consistent-hash lookup tables, connection tracking and scaling out behind ECMP.

    Open(opens in a new tab)Link responded, 5 Oct 2026
  • Computer Networks: A Systems Approach

    Systems Approach (open online edition)

    Section: 9.4 Overlay Networks

    How content distribution networks redirect clients to nearby caches and what they speed up.

    Open(opens in a new tab)Link responded, 5 Oct 2026

Step 4: Practice

Run two copies of a small HTTP service behind a local reverse proxy (nginx, HAProxy or Envoy). Send load once with an HTTP/1.1 client that opens many connections and once with an HTTP/2 client that uses a single connection, and compare how requests are spread. Stop one backend mid-test to see what health checking and retries do. Use the request-timing project against a site served through a CDN to see where TLS terminates and how much the edge saves.

Record attempts on each problem’s page (+15 XP, +10 more when solved on your own).

Step 5: Test yourself

Answer each one out loud or on paper before you finish the lesson.

  1. Question 1What can an L7 balancer do that an L4 balancer cannot, and what does it cost?
  2. Question 2Why does least-outstanding-requests reduce tail latency compared with round robin?
  3. Question 3Roughly what fraction of keys move when a backend is added under modulo hashing versus consistent hashing?
  4. Question 4What goes wrong if every proxy layer retries three times?
  5. Question 5How does a backend learn the original client IP address behind a reverse proxy?
  6. Question 6Which HTTP headers decide whether a CDN may cache a response, and what does Vary do?

You’re done when you can

  • Explain with a gRPC example why an L4 balancer can overload one backend, and give two fixes.
  • Explain how consistent hashing limits remapping when one of N backends is removed.
  • Design and justify a health-checking scheme for a service with a shared database dependency.
  • Explain what a CDN speeds up for an uncacheable API request.

Finish the lesson

How confident do you feel?

Lesson complete!

+50 XP

Reviews will come up on the Practice tab so it sticks.

Unlocks next: Kubernetes and container orchestration

Your notes and study time

Log study time