Reverse Proxy vs Load Balancer
Ask what Nginx is and you may hear "a reverse proxy" or "a load balancer". Both answers are right, which is exactly why the two terms get mixed up. They describe different goals that one product can serve.
This tutorial separates the two ideas: what each one is for, where they overlap, and when you need one, the other, or both. It assumes you have read Reverse Proxy and Load Balancing.
1. What Are a Reverse Proxy and a Load Balancer?
A reverse proxy is an intermediary that receives requests for one or more servers and forwards them, adding services such as TLS termination, caching, compression and request filtering. Its purpose is to front servers.
A load balancer distributes incoming traffic across multiple instances of a service, using an algorithm and health checks, to improve capacity and availability. Its purpose is to spread work.
Most Layer 7 load balancers are reverse proxies with balancing features. Some Layer 4 load balancers forward packets without being proxies at all.
Cloud products blur the line further. AWS Application Load Balancer, for example, is a managed Layer 7 reverse proxy sold under the load balancer name.
2. Architecture Comparison
3. How Each One Handles a Request
Reverse proxy with a single backend
A small company runs one application server. The reverse proxy in front of it terminates HTTPS, serves cached product images, compresses HTML and blocks oversized uploads. No balancing happens, yet the proxy is clearly useful.
Load balancer with three instances
- A request arrives at the load balancer.
- Health checks have marked instance 3 as down, so only instances 1 and 2 are candidates.
- The algorithm, for example Least Connections, picks instance 2.
- The request is forwarded; if instance 2 fails mid-request, a Layer 7 balancer can retry on instance 1 for safe, idempotent requests.
Health checks in practice
Active health checks send a probe, such as GET /actuator/health, every few seconds and remove an instance after several failures. Passive checks watch real traffic: in open-source Nginx, max_fails=3 fail_timeout=20s marks a server unavailable for 20 seconds after three failed attempts within that period. Spring Boot exposes a ready-made health endpoint through Actuator, and Kubernetes uses readiness probes so that a Service sends traffic only to pods that are ready.
4. Where They Overlap and Where They Differ
- Overlap: both sit in front of servers, hide them from clients, and can terminate TLS. Nginx, HAProxy and Envoy do both jobs.
- Only the load balancer needs multiple identical backends, a balancing algorithm and health-check-driven failover.
- Only the reverse proxy concept covers routing different paths to different applications, caching, compression and response rewriting, even with a single backend.
- Layer matters: a Layer 4 load balancer such as AWS NLB balances TCP connections without reading HTTP, so it does none of the reverse proxy's HTTP features.
Session persistence
Load balancers often support sticky sessions, which keep a user on one instance by using a cookie or an IP hash. A reverse proxy with a single backend never needs this. Stickiness helps legacy applications that keep session data in memory, but it causes uneven load and lost sessions when an instance fails. Modern services store sessions in Redis or use stateless tokens such as JWTs, so any instance can serve any request.
5. Practical Implementation
Nginx as a pure reverse proxy (one backend)
server {
listen 443 ssl;
server_name blog.example.com;
ssl_certificate /etc/nginx/certs/blog.crt;
ssl_certificate_key /etc/nginx/certs/blog.key;
gzip on;
location / {
proxy_pass http://127.0.0.1:8080; # a single app server
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Nginx as a load balancer (many backends)
upstream orders {
least_conn;
server 10.0.1.11:8080 max_fails=3 fail_timeout=20s;
server 10.0.1.12:8080 max_fails=3 fail_timeout=20s;
server 10.0.1.13:8080 backup; # used only if the others fail
}
server {
listen 80;
location / {
proxy_pass http://orders;
proxy_next_upstream error timeout http_502 http_503;
}
}
Kubernetes: load balancing built in
In Kubernetes, a Service already balances connections across matching pods, while an ingress controller adds the reverse proxy layer for HTTP routing and TLS.
apiVersion: v1
kind: Service
metadata:
name: orders
spec:
selector:
app: orders # every ready pod with this label receives traffic
ports:
- port: 8080
targetPort: 8080
6. Advantages and Disadvantages
| Reverse proxy | Load balancer | |
|---|---|---|
| Main benefit | Security, TLS, caching and routing in one place | Horizontal scaling and high availability |
| Works with one server | Yes | Not meaningful |
| Protocol awareness | HTTP features | Layer 4 or Layer 7 depending on type |
| Main drawback | Extra hop; must be redundant | Needs health checks and tuning; Layer 4 lacks HTTP features |
7. Reverse Proxy vs Load Balancer Comparison
| Aspect | Reverse proxy | Load balancer |
|---|---|---|
| Primary goal | Front and protect servers | Distribute traffic across instances |
| Backends | One or many, possibly different apps | Many identical instances |
| Algorithms and health checks | Optional | Core features |
| Caching and compression | Common | Only in Layer 7 products |
| OSI layer | Layer 7 | Layer 4 or Layer 7 |
| Examples | Nginx, Caddy, Apache httpd | AWS ALB/NLB, HAProxy, Nginx upstream, Kubernetes Service |
8. Real-World Use Cases
- Reverse proxy only: a single WordPress or Spring Boot server that needs HTTPS, caching and protection.
- Load balancer only: a Layer 4 balancer spreading TCP connections across database replicas or message brokers.
- Both: a cloud Layer 4 or Layer 7 balancer in front of several reverse proxies or ingress controllers, which route to services that are themselves balanced.
A good one-line interview answer: every Layer 7 load balancer is a reverse proxy, but a reverse proxy becomes a load balancer only when it has several equivalent backends to choose from.
A typical growth path
- Start with one application server behind Nginx as a reverse proxy for HTTPS and compression.
- When traffic grows, add a second server and turn the single
proxy_passaddress into anupstreamgroup. The reverse proxy now also load balances. - For high availability, run two proxy instances behind a cloud load balancer or a floating IP.
- At larger scale, split the responsibilities: a managed load balancer at the edge, and reverse proxies or an ingress controller per environment.
Each step adds one capability only when the system actually needs it.
9. Best Practices
- Describe the role, not the product: "Nginx as reverse proxy" and "Nginx as load balancer" are different responsibilities.
- Add balancing early: even two instances behind a balancer remove a single point of failure.
- Use active health checks where available, plus passive failure detection.
- Retry only idempotent requests to avoid double charges or duplicate orders.
- Keep the front tier redundant: the proxy or balancer itself needs a failover partner.
- Drain connections before removing an instance so in-flight requests can finish during deployments.
Finally, measure the distribution. Per-instance request counts and latency show whether the algorithm, weights and health checks are working, and reveal a "hot" instance long before users notice slow responses.
10. Summary
- A reverse proxy fronts servers; a load balancer spreads load across them.
- Most Layer 7 load balancers are reverse proxies with algorithms and health checks.
- A reverse proxy is useful with one server; a load balancer needs several.
- Layer 4 balancers distribute connections without HTTP features.
- Large systems usually combine both, often in the same software.
Next, see how a globally distributed reverse proxy works in Reverse Proxy vs CDN.
Reverse Proxy vs Load Balancer: Top Interview Questions
These are the reverse proxy and load balancer questions most often asked in system design interviews, with short answers you can explain in your own words.
Q1. Is a load balancer the same as a reverse proxy?
Not exactly. A Layer 7 load balancer is a reverse proxy that focuses on spreading traffic across instances. A reverse proxy can be useful with a single server, and some Layer 4 load balancers are not proxies at all.
Q2. Can Nginx be both a reverse proxy and a load balancer?
Yes. proxy_pass to a single address makes it a reverse proxy; proxy_pass to an upstream group with several servers adds load balancing with an algorithm and failure detection.
Q3. When would you need a reverse proxy but not a load balancer?
When you have one application server but still want HTTPS termination, caching, compression or protection from direct internet access.
Q4. What does a load balancer do when a server fails?
Health checks, active or passive, mark the server as unhealthy, and the balancer stops sending it traffic. A Layer 7 balancer can retry failed idempotent requests on another healthy server.