Topic 029 / Core
Reverse proxy and forward proxy
Chapter 3.3 · Proxies and the Request Path
What and why
A server should not terminate TLS, cache, compress, and run business logic all inside the same application process; and a client often should not talk to the open internet directly either. A proxy is an intermediary that relays HTTP (→ 28) requests on someone's behalf. A forward proxy sits in front of clients (egress control, anonymity, content filtering). A reverse proxy sits in front of servers (TLS termination, compression, routing, buffering), presenting one address to the outside world in place of whatever is actually behind it. Builds on: → 28.
Diagram
Forward proxy: client ──► forward proxy ──► internet ──► destination server
Reverse proxy: client ──► internet ──► reverse proxy ──► {server 1, server 2, ...}
How it works
- Reverse proxy: the client connects to the proxy's public address, unaware anything else exists behind it.
- The proxy may terminate TLS (→ 27) there, so individual backend servers don't each need their own certificate.
- The proxy inspects the request and decides which backend should handle it.
- The proxy forwards the request to that backend and relays the response back, optionally caching or compressing it along the way.
- Forward proxy: a client is configured to send all outbound requests through the proxy, which applies policy (allow, block, log) before forwarding to the real destination on the client's behalf.
Practical example
(illustrative). One reverse proxy sits in front of several identical backend instances, presenting a single public address; every client request looks, from the outside, like a direct connection to "the server" — the fact that there are several, or that one just failed and traffic shifted to another, is invisible to the client.
When to use it
- Use when: there is more than one backend instance, or TLS termination needs centralizing instead of repeating on every instance; use a forward proxy to control or audit outbound traffic from a fleet of clients.
- Avoid when: a single-instance hobby project adds a proxy layer for no benefit yet — one more moving part to operate with nothing behind it to route between.
- Failure scenarios: the proxy itself becomes a single point of failure if it isn't redundant; a misconfigured routing rule silently sends traffic to the wrong backend; a compromised forward proxy sees every client's outbound traffic.
- Simpler alternative: a direct client-to-server connection, when there is exactly one server and no TLS-termination or routing need to centralize.
Practice
(pattern kind — implement minimal; 20–30 min, no lab services). Run two small HTTP servers and put a reverse proxy in front of them (a config-only tool, or a dozen lines of code), routing by path to one or the other. Stop one backend and observe what the proxy does with requests meant for it. Done when you can state, from what you observed, whether the proxy degrades gracefully or fails the whole route.
Key takeaway
A reverse proxy acts for servers; a forward proxy acts for clients — both let one layer handle cross-cutting concerns instead of repeating them everywhere. Done when you can: say, for a given request path, which side the proxy is acting for and what it is centralizing. Used next in → 30, 41 (the API gateway is a reverse proxy with more responsibilities).
References
None — this topic makes no external claims.
Source directory