CodePark/ questions / Load balancing & proxies
START PRACTICINGPRACTICE
Backend question · System design & architecture › Load balancing & proxies

Explain the difference between a reverse proxy, a load balancer and an API gateway. Why do people mix them up?

The three differ by their main job: a reverse proxy hides servers, a load balancer spreads load, and an API gateway manages an API.

A reverse proxy sits in front of servers. It forwards client requests to them, so clients never see the backends. Typical jobs:

  • TLS termination (decrypting HTTPS)
  • compression
  • caching static responses
  • buffering slow clients

Example: Nginx in front of a single Node app is a reverse proxy.

A load balancer spreads traffic across several copies (instances) of the same service. It runs health checks and skips unhealthy instances. It can work at L4 (TCP) or L7 (HTTP). An L7 load balancer is a kind of reverse proxy.

An API gateway is a reverse proxy made for APIs. It is a single entry point for clients, and it routes to many different services. It also handles cross-cutting concerns, meaning jobs every service needs:

  • authentication
  • rate limiting
  • API keys
  • request aggregation (combining several service calls into one response)
  • protocol translation

People mix them up because one product often does all three jobs. The roles are still different.

  • A reverse proxy sits in front of servers and hides them, and it often handles TLS and caching.
  • A load balancer spreads load across instances and uses health checks.
  • An API gateway is a single entry point that routes to many services.
  • An API gateway handles auth, rate limiting and aggregation.
  • The same tool can play several of these roles.