CSE Roadmap

Core tier · about 3 hours · 9 parts

Part 4 of 9 · 2 min read

The reverse proxy and what it adds

A middleman in front of servers, and the jobs it takes over.

Think of a hotel reception. Guests never walk into the kitchen or the offices. They speak to the desk, and the desk talks to the staff.

A proxy is a middleman. There are two kinds, and the difference is which side it serves.

Forward proxy and reverse proxy

A forward proxy sits in front of clients and speaks for them to the internet. A reverse proxy sits in front of servers and speaks for them to the internet.

Example: an office network that sends all employee traffic through one gateway is a forward proxy. A website that accepts all traffic at one machine, and passes it on to hidden servers, is a reverse proxy.

A layer 7 load balancer is a reverse proxy that also balances. A reverse proxy takes over jobs that every server would otherwise repeat.

Job What it means
TLS termination The proxy does the secret-key work, and talks plain or lightly protected HTTP to servers inside the private network
Compression The proxy shrinks text replies before they cross the internet
Caching The proxy keeps copies of replies for popular paths (Level 3)
Hiding The servers' addresses and software stay unseen
Connection reuse The proxy keeps long-lived connections to servers and shares them among many client requests
Protection The proxy blocks bad requests and limits the rate
Retry The proxy sends the request to another server if one fails

A worked example for TLS termination. On page 1, TLS added round trips at the start of a connection. Suppose a user is 20 milliseconds from a nearby proxy, the origin servers are 120 milliseconds from the user, and TLS needs 2 round trips (made up for the example).

  • Proxy near the user ends TLS. The handshake runs over the short path: 2 × 20 = 40 ms. The proxy keeps warm connections open to the far servers, so the user does not pay the long path for the handshake.
  • No nearby proxy. The handshake runs all the way to the far servers: 2 × 120 = 240 ms.
  • The saving is 240 − 40 = 200 ms on every new connection.

A proxy placed near users, with fast inside links, keeps the long path short. It reuses a few warm connections to the servers, instead of opening a new one for each user.

The book offers one more option for traffic between a company's own services. The balancing is put on the client side of each call as a small helper process on the same machine, called a sidecar. This removes one shared balancer that must be scaled. The cost is more moving parts. Level 7 covers it.

For the curious For the curious

Common proxy software includes NGINX, HAProxy and Envoy. Cloud providers sell managed balancers for both layers. In an interview, naming the layer is more useful than naming a product.

Check yourself:

  • Which side does a reverse proxy serve?
  • Name two jobs a proxy can take away from each web server.