FOUNDATIONS / SYSTEM CONCEPT BRIEF

Reverse proxy

A reverse proxy receives client requests on behalf of one or more backend servers.

BeginnerPhase 01 / Topic 10 of 17RequirementsTrade-offsFailure modes
01

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.

A hotel front desk

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.

02

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).
03

Where it shows up in interviews

Front door of a web app

Recognize it when: multiple app servers, one public entry point.

  • Design a scalable web application
  • Design Instagram's web tier
Path-based routing

Recognize it when: migrate a monolith gradually by routing paths to new services.

  • Strangler fig migration
  • Design an API gateway
04

Where it is used in real software

Nginx in front of Node, Python, and Rails apps

App servers run on local ports; Nginx handles TLS, static assets, gzip, and load balancing.

Cloudflare

A global reverse proxy that caches content, blocks attacks, and forwards the rest to your origin.

Kubernetes Ingress

Ingress controllers (Nginx, Traefik, Envoy) are reverse proxies routing external traffic to cluster services.

05

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.
06

How it works, step by step

  1. 1
    Accept and decrypt

    The proxy terminates TLS and parses the HTTP request.

  2. 2
    Check cache

    Serve cached responses immediately when valid.

  3. 3
    Route

    Match host and path rules to pick an upstream group.

  4. 4
    Balance and forward

    Pick a healthy instance and forward over a pooled connection.

  5. 5
    Transform the response

    Compress, add security headers, cache, and log.

Reverse proxy routing by path
Step 1 / 4
Client
Reverse proxy
Cache
API service
Web app

STEP 1An HTTPS request for /api/orders arrives; the proxy terminates TLS.

07

What moves from the app into the reverse proxy

Responsibilities before and after adding a proxy

Step 1 / 5
ConcernWithout proxyWith reverse proxy
TLS certificatesEvery app instanceOne place
Static filesApp process (slow)Served directly, cached
CompressionApp codeProxy config
Slow clientsTie up app workersBuffered by proxy
Multiple instancesClients must know themHidden 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.

08

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;    }}
09

Complexity and performance

Added latency< 1 ms

Same region.

Throughput per Nginx node10k-100k+ req/s

Depends on TLS and payload.

10

Trade-offs

Single point of failure

Run at least two proxy instances (or a managed load balancer) across availability zones.

Configuration complexity

Rules accumulate; manage configuration as code and test it.

11

Variants and related techniques

Load balancer

A reverse proxy focused on distribution and health checks.

API gateway

Adds API keys, quotas, and request transformation.

Ingress controller

Kubernetes-native reverse proxy.

12

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.

13

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.

14

Practice problems

ProblemDifficultyWhat it trains
Configure path routing for two servicesEasyRouting rules.
Migrate a monolith route by route to microservicesMediumStrangler pattern.