← Back to System Design, page 2

system-design-0029 · Easy fresher

What is the difference between a forward proxy, a reverse proxy and an API gateway?

A forward proxy acts for clients, sending their requests out to the internet, for example a school network filter. A reverse proxy acts for servers, receiving public requests and forwarding them to internal backends, adding TLS termination, caching, compression and load balancing. An API gateway is a reverse proxy specialised for APIs, adding authentication, rate limiting, routing to many services, request transformation and API keys.

Full answer

Forward proxy

Sits in front of clients. The client is configured to send requests through it.

  • A school or office network sends all browsing through a proxy that blocks some sites and logs usage.
  • It can cache popular downloads for the whole network.
  • It hides the client's IP address from the destination.

The website sees the proxy, not the student's laptop.

Reverse proxy

Sits in front of servers. Clients think they are talking to the website; the proxy forwards to a backend they never see.

  • TLS termination: handles HTTPS certificates in one place.
  • Load balancing across app servers.
  • Caching and compression of responses.
  • Security: hides internal topology, filters bad requests, absorbs slow clients.

Nginx, HAProxy, Envoy and Caddy are common reverse proxies. A minimal Nginx example (configuration sketch, not run here):

nginx
upstream app_servers {
    server 10.0.0.11:8080;
    server 10.0.0.12:8080;
}

server {
    listen 443 ssl;
    server_name learn.example.com;
    ssl_certificate     /etc/ssl/learn.crt;
    ssl_certificate_key /etc/ssl/learn.key;

    location /static/ {
        root /var/www;
        expires 30d;
    }

    location / {
        proxy_pass http://app_servers;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

API gateway

A reverse proxy with API-specific features, usually the single entry point for many microservices:

  • Route /payments/* to the payments service, /courses/* to the catalogue service.
  • Verify OAuth tokens or API keys before requests reach services.
  • Apply rate limits and quotas per client or plan.
  • Transform requests (REST to gRPC), aggregate responses, add request IDs for tracing.
  • Collect per-API metrics.

Examples: Kong, Amazon API Gateway, Apigee, Envoy-based gateways.

Cautions

The gateway is on every request, so it must be horizontally scaled and redundant. Keep business logic out of it; it should route and protect, not compute prices. A load balancer, reverse proxy and gateway are often stacked: a cloud L4 load balancer in front of a gateway fleet in front of services.

By level

Fresher: Explain forward versus reverse proxy with simple examples and list what a reverse proxy does. Saying who each proxy works for is the key point.

Mid: Configure a reverse proxy conceptually, explain gateway features, and where authentication and rate limiting should live. Expect the backend to read the real client IP correctly.

Senior: Discuss layering of load balancers, gateways and service mesh, gateway scaling and failure modes, multi-region edge routing, and governance of shared gateway configuration. It should explain why business logic stays out of the gateway.

Key points

  • Forward proxy represents clients; reverse proxy represents servers
  • Reverse proxies terminate TLS, balance load, cache and compress
  • API gateways add auth, rate limits, routing and transformation for APIs
  • The gateway must be scaled and redundant
  • Keep business logic out of the gateway

Common mistakes

  • Mixing up forward and reverse proxies
  • Putting business logic in the gateway
  • Forgetting X-Forwarded-For when the backend needs the client IP
  • Making the gateway a single point of failure

Follow-ups

  • How does the backend learn the real client IP behind a proxy?
  • Where would you verify JWTs: gateway or service?
  • What is a service mesh and how does it differ from a gateway?

Tips

  • Say who the proxy works for in the first sentence
  • List three reverse proxy jobs
  • Name what the gateway adds beyond a reverse proxy

Evaluation rubric

  • Correct direction of each proxy type
  • Lists reverse proxy responsibilities
  • Explains API gateway features
  • Mentions availability and scope concerns