Overview
A reverse proxy receives client requests on behalf of one or more backend servers. Clients only ever see the proxy's address; the proxy decides which backend handles each request, forwards it, and returns the response. It is the standard front door of almost every production web system.
Because every request passes through it, the reverse proxy is the natural place for shared concerns: TLS termination, load balancing, caching, compression, request buffering, security headers, rate limiting, and routing by host or path. Offloading these keeps application servers simple and focused on business logic.
Guests never walk into the kitchen or housekeeping office. They talk to the front desk, which routes requests to the right department, handles common questions directly (cached answers), and keeps the staff areas secure.
When to use it
- Exposing multiple backend instances behind one address.
- Terminating TLS in one place.
- Serving static files and caching responses.
- Routing /api to one service and /app to another.
- Protecting slow app servers from slow clients (buffering).
Where it shows up in interviews
Recognize it when: multiple app servers, one public entry point.
- Design a scalable web application
- Design Instagram's web tier
Recognize it when: migrate a monolith gradually by routing paths to new services.
- Strangler fig migration
- Design an API gateway
Where it is used in real software
App servers run on local ports; Nginx handles TLS, static assets, gzip, and load balancing.
A global reverse proxy that caches content, blocks attacks, and forwards the rest to your origin.
Ingress controllers (Nginx, Traefik, Envoy) are reverse proxies routing external traffic to cluster services.
Key terms
- Upstream / origin
- The backend servers the proxy forwards to.
- TLS termination
- Decrypting HTTPS at the proxy.
- Request buffering
- The proxy receives the full request before sending it upstream, protecting backends from slow clients.
- Path / host routing
- Choosing an upstream based on the URL path or Host header.
How it works, step by step
- 1Accept and decrypt
The proxy terminates TLS and parses the HTTP request.
- 2Check cache
Serve cached responses immediately when valid.
- 3Route
Match host and path rules to pick an upstream group.
- 4Balance and forward
Pick a healthy instance and forward over a pooled connection.
- 5Transform the response
Compress, add security headers, cache, and log.
STEP 1An HTTPS request for /api/orders arrives; the proxy terminates TLS.
What moves from the app into the reverse proxy
Responsibilities before and after adding a proxy
| Concern | Without proxy | With reverse proxy |
|---|---|---|
| TLS certificates | Every app instance | One place |
| Static files | App process (slow) | Served directly, cached |
| Compression | App code | Proxy config |
| Slow clients | Tie up app workers | Buffered by proxy |
| Multiple instances | Clients must know them | Hidden behind one address |
NOWConcern: TLS certificates | Without proxy: Every app instance | With reverse proxy: One place
The app becomes simpler and scales by adding instances behind the proxy, while cross-cutting policies live in one configuration.
Implementation
upstream api { server 10.0.1.10:8080; server 10.0.1.11:8080; keepalive 32; }upstream web { server 10.0.2.10:3000; } proxy_cache_path /var/cache/nginx keys_zone=pages:50m max_size=1g inactive=10m; server { listen 443 ssl http2; server_name app.example.com; gzip on; location /api/ { proxy_pass http://api; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /static/ { root /var/www; # served without touching the app expires 1y; } location / { proxy_cache pages; proxy_cache_valid 200 60s; proxy_pass http://web; }}Complexity and performance
Same region.
Depends on TLS and payload.
Trade-offs
Run at least two proxy instances (or a managed load balancer) across availability zones.
Rules accumulate; manage configuration as code and test it.
Variants and related techniques
A reverse proxy focused on distribution and health checks.
Adds API keys, quotas, and request transformation.
Kubernetes-native reverse proxy.
Common mistakes
- Caching personalized pages.
Fix: Vary cache keys on user identity or bypass the cache for authenticated requests.
- Not forwarding the original scheme and IP.
Fix: Set X-Forwarded-Proto and X-Forwarded-For so the app generates correct URLs and logs.
Interview questions
What is the difference between a reverse proxy and a load balancer?
Every load balancer is a reverse proxy, but a reverse proxy can do more than balance: caching, TLS, routing, compression, and security filtering. Many products do both.
Why does buffering in the proxy help?
Slow mobile clients can take seconds to send or receive data. The proxy absorbs that slowness so each app worker is busy only for the short time it processes the request.
Practice problems
| Problem | Difficulty | What it trains |
|---|---|---|
| Configure path routing for two services | Easy | Routing rules. |
| Migrate a monolith route by route to microservices | Medium | Strangler pattern. |