Reverse Proxy Use Cases and Tools: NGINX, HAProxy and Envoy
Overview
A reverse proxy is the front door of many systems. This lesson walks through the jobs it commonly does, the difference between working at the TCP level and the HTTP level, and the popular tools you will hear about in interviews.
Detailed Notes
What does a reverse proxy do
Think of the reverse proxy as the one place where jobs common to every backend server are done once, instead of repeating them on each server.
The problem it solves
An online store runs on five servers. Each has its own TLS certificate, its own compression and its own bot protection. Renewing certificates means touching five machines, and a bug in one server's protection lets a bot hammer it. Deployments drop customers' requests.
Put a reverse proxy in front and the certificates live in one place, bots are handled centrally, and a deployment can shift traffic away from a server gracefully. The application servers get simpler.
How it works
Common jobs:
- TLS termination: the proxy decrypts HTTPS, backends receive plain HTTP (or re-encrypted traffic). The alternative, TLS passthrough, forwards the encrypted stream untouched: end-to-end encryption, but the proxy cannot see inside.
- Routing: pick a backend by host name or path. /api goes to the API service, /images to storage: one public address, many services.
- Load balancing: spread requests over several servers (covered in its own chapter).
- Caching and compression: serve repeated answers without bothering the backend and send smaller responses (caching is covered later).
- Security and limits: block known attack patterns, limit requests per client, check login tokens before forwarding.
- Connection management: keep many slow client connections open while reusing a small pool of connections to the backends.
- Protocol translation: speak newer HTTP versions to clients and older ones to backends.
Health checks, timeouts, retries. The proxy probes backends and stops sending traffic to failing ones. Timeouts stop a slow backend from tying up resources. Failed requests that are safe to repeat (idempotent) can be retried on another server, but retries must be limited, or they multiply load during an outage.
Layer 4 vs Layer 7. In the network chapter you met the layers of networking. A Layer 4 proxy works at the transport layer (TCP/UDP: it sees IP addresses and ports and just passes bytes along). A Layer 7 proxy works at the application layer, so it understands HTTP: URLs, headers and cookies (small pieces of data the browser stores and sends back with each request).
| Layer 4 (TCP/UDP) | Layer 7 (HTTP) | |
|---|---|---|
| Sees | IP addresses, ports, bytes | URLs, headers, cookies, methods |
| Speed | Faster, simpler | A bit more work per request |
| Features | Balancing, TLS passthrough | Path routing, caching, security rules, header changes |
| Use | Databases, non-HTTP traffic | Web apps and APIs |
Popular tools:
- NGINX: fast web server and reverse proxy. Great for static content, TLS termination and simple configuration. Very common as a web front end.
- HAProxy: a very efficient load balancer working at Layer 4 and 7, with rich health checks.
- Envoy: modern proxy built for cloud-native systems. Configured dynamically through APIs, with rich metrics and retry support.
- Others: Apache, Traefik, Caddy, and managed cloud load balancers.
Avoid a single point of failure. Because everything flows through the proxy, run several instances, and test configuration changes carefully: a bad rule affects all traffic.
A simple example
A hotel front desk checks your booking, verifies your ID, and then sends you to the right floor. The rooms (servers) do not each need their own security desk.
System design example
A shop's traffic arrives at a small cluster of NGINX proxies. They terminate TLS, send /api requests to API servers and /static to a file server, and apply a request limit per client. HAProxy or a cloud load balancer in front of the proxies spreads incoming connections across them so no single proxy is a bottleneck or single point of failure. When the team deploys a new version, the proxies drain a server, wait for requests to finish, and then switch.
Summary
- A reverse proxy does shared jobs once: TLS, routing, limits, compression.
- TLS termination decrypts at the proxy; passthrough keeps end-to-end encryption.
- Layer 4 proxies see only TCP; Layer 7 proxies understand HTTP.
- NGINX, HAProxy and Envoy are the names to know.
- Run several proxies, and treat their configuration as critical.
Architecture Diagram
One tier handles TLS, routing and protection in front of the backends.
- 1Users connect to the proxy's public address over HTTPS.
- 2The proxy decrypts the traffic and checks the request.
- 3It routes by path to the matching backend.
- 4The response flows back through the proxy to the user.
Common Interview Questions
Chapter quiz
Proxies · 4 questions
1.Which proxy sits in front of clients and hides their identity from servers?
2.How does a backend normally learn the real client IP behind a reverse proxy?
3.What is TLS termination?
4.A Layer 7 proxy can do what a Layer 4 proxy cannot:
0 of 4 answered
Finished this lesson?
0 of 91 lessons done · 0% of the course

