What it is
A reverse proxy is a server that sits in front of one or more application servers and receives client requests on their behalf. Clients connect to the proxy's public address; the proxy opens its own connection to a backend, forwards the request and relays the response. The backends are usually on a private network and unreachable from the internet.
A forward proxy is the mirror image: it acts for clients (for example a corporate egress proxy or a privacy proxy) and hides them from the servers they visit. A load balancer is a reverse proxy whose main job is spreading traffic over several backends; most modern reverse proxies (nginx, HAProxy, Envoy) do both.
Why it exists
Exposing application servers directly couples clients to specific machines and forces every server to deal with the internet: TLS, slow clients, abusive traffic, compression and static files. A single front door decouples clients from servers and lets you implement those cross-cutting concerns once, in software built for them, instead of in every application.
How it works
Connection handling. The proxy accepts client connections, often terminates TLS, and reads the request. It then picks a backend (by host, path, header or a balancing algorithm) and sends the request over a separate connection, typically a pooled, keep-alive connection on the private network.
Common responsibilities:
- TLS termination: certificates and handshakes live in one place; backends speak plain HTTP or internal mTLS.
- Routing:
/api/*to the API service,/static/*to object storage,admin.example.comto another service. - Compression and caching: gzip or Brotli responses; serve cached responses without touching the backend.
- Buffering: absorb slow uploads and downloads so application workers are not held hostage by slow networks.
- Protection: request size limits, rate limits, IP allow and deny lists, basic web application firewall rules.
- Resilience: health checks, retries of idempotent requests on another backend, timeouts.
- Observability: access logs, request IDs and metrics for every request in one format.
Rate limiting. A token bucket per key (client IP, API key, user) refills at a fixed rate up to a burst size. Each request takes a token; without one the proxy answers immediately with HTTP 429, often with a Retry-After header. The excess costs almost nothing, and the backends stay within capacity.
When to use it
- Any internet-facing web application or API: almost every production deployment has one.
- When several services share one domain and need routing by path or host.
- When you want TLS, compression, logging and rate limits handled consistently.
- In front of servers you want to scale, replace or deploy without clients noticing.
When not to
- Internal service-to-service calls where a service mesh sidecar or client-side balancing already provides the same features; another central proxy adds a hop.
- Extremely latency-sensitive paths where even a local hop matters and the features are not needed.
- Protocols the proxy cannot understand, where only a layer-4 pass-through makes sense.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Reverse proxy in front | Hidden, replaceable servers; central TLS, routing, limits | An extra hop; a critical component to run |
| TLS terminated at the proxy | Simpler backends, one place for certificates | Traffic inside the network is plaintext unless re-encrypted |
| Caching at the proxy | Fewer backend requests, lower latency | Invalidation and staleness to manage |
| Rate limiting at the proxy | Backends protected, abuse contained | Legitimate bursts may be rejected; limits need tuning per client |
| Proxy retries | Hides brief backend failures | Duplicate work; dangerous for non-idempotent requests |
Alternatives
- Managed load balancers (cloud layer-7 balancers): the same role, operated for you.
- API gateways: reverse proxies specialised for APIs, adding authentication, quotas, request transformation and developer keys.
- CDNs: globally distributed reverse proxies that cache at the edge, close to users.
- Service meshes: a small proxy next to every service instance, for internal traffic.
- Client-side load balancing: clients discover backends themselves and connect directly.
Failure modes
- Single point of failure: one proxy instance down means every request fails, however healthy the backends are.
- Proxy saturation: CPU for TLS, connection limits or file descriptors run out before the backends do.
- Misrouting: a configuration error sends traffic to the wrong backend or drops a path entirely; configuration changes need review and staged rollout.
- Timeout mismatch: a proxy timeout shorter than the backend's work makes clients retry requests that are still running; a longer one ties up connections.
- Retry amplification: proxy retries on top of client retries multiply load during an incident.
- Lost client information: without
X-Forwarded-Foror theForwardedheader, backends see the proxy's IP instead of the client's.
In production
Run at least two proxy instances across availability zones, behind a floating IP, DNS with health checks, or a managed network load balancer. Keep configuration in version control and roll it out gradually. Set explicit timeouts, body size limits and per-client rate limits; forward the original client IP and protocol in standard headers; and propagate a request ID for tracing. Monitor the proxy's own latency, error rate, connection counts and certificate expiry alongside backend metrics. Common choices are nginx, HAProxy, Envoy, Caddy and Traefik, or the cloud provider's layer-7 balancer.
Common misconceptions
- "A reverse proxy is only for load balancing." Routing, TLS, caching, buffering and protection are often the main reasons to have one, even with a single backend.
- "It makes the system slower." The extra hop costs a millisecond or two inside a data centre, and offloading TLS, compression and slow clients often makes the whole system faster.
- "It removes single points of failure." It hides backend failures but is itself one unless run redundantly.
- "Forward and reverse proxies are the same thing." They sit on opposite sides and serve opposite parties.
Interview angle
In a system design interview the reverse proxy or load balancer is usually the first box after the client. Name what it does beyond balancing: TLS termination, routing by path, rate limiting and caching. Expect follow-ups on how you make it highly available, where TLS ends, how backends learn the client's IP, and how rate limits are keyed. Mentioning that CDNs and API gateways are specialised reverse proxies shows you see the pattern.
Model assumptions
The simulation is a simplified model, not a benchmark. The reverse proxy is modelled as a load balancer with round robin, 1 ms of processing, health checks every 500 ms (2 failures eject, 3 successes restore) and an optional token-bucket rate limit (60 requests per second with a burst of 20). App servers have 6 workers, an 80 ms mean service time (lognormal, cv 0.35) and room for 12 waiting requests. TLS, compression, path routing and caching are described but not simulated; the static file store is drawn for illustration only. Arrivals are random (Poisson); network hops take a fixed 1–30 ms. Numbers show behaviour and orders of magnitude only.