Dev Learning

Reverse proxies and gateways

One front door that handles the boring, repeated work before anything reaches your code.

1

What problem does reverse proxies solve?

A reverse proxy sits in front of your servers and receives every request first. Clients talk to it, and it talks to your services. It gives you one place to do the work that every service would otherwise repeat.

That work is: handling HTTPS, compressing responses, serving static files, rate limiting, checking logins, routing by path, and logging.

2

What reverse proxies costs you

What it costs you
One more hop, one more thing to configure, and one more thing that can be set up wrongly in a way that affects everything at once. It is also a single point of failure unless you run more than one. And putting too much logic in it creates a part that nobody owns and that everything depends on.

Every concept in here states a cost. A technique with no price is a technique you have not understood yet — and naming the cost out loud is most of what separates a senior answer from a junior one.

3

When to reach for reverse proxies, and when not to

Use it when

  • Anything that should happen the same way for every request: TLS, compression, request logging, rate limits.
  • Putting several services behind one domain, routed by path.
  • Hiding your internal layout from the outside world.
  • Serving static files, so application servers never see those requests.

Do not, when

  • Business logic. Once routing rules start expressing product decisions, you have a distributed system living in a config file.
  • A single service with nothing shared to do. Then it is a hop for nothing.
4

How reverse proxies actually works

httpshttpClientsReverse proxyTLS, gzip, limits/api/static/ws
The proxy does the repeated work once, so no service needs its own TLS, compression or rate limiting.

People get asked how a reverse proxy differs from a load balancer. They overlap a lot, and the same software usually does both. The difference is purpose. A load balancer exists to spread traffic across several identical servers. A reverse proxy exists to be a front door, and it is useful even with one server behind it, because it still handles TLS and serves static files. In practice nginx, Envoy and most cloud load balancers do both jobs. Say that, rather than pretending they are separate boxes.

An API gateway is a reverse proxy with stronger opinions. It checks logins, applies per-customer rate limits, reshapes requests, and often combines several backend calls into one response. It is the natural home for the things every public API needs. The risk is that it grows until it holds business logic, and then deploying anything means deploying the gateway.

A forward proxy is the mirror image, and it deserves one sentence so the names do not confuse you. It sits in front of *clients* rather than servers. It is what a company uses to control and inspect traffic leaving its own network.

Two things catch people out. First, if TLS ends at the proxy, then traffic behind it is plain HTTP. That is fine inside a trusted network and not fine across the public internet, so know which one you have. Second, the proxy is where the client's real IP address gets lost. That is why X-Forwarded-For exists, and why rate limiting by IP breaks if you forget to read it. Trust that header only when your own proxy set it, because clients can send it too.

Common trap
  • Forgetting the proxy needs a backup of its own. It is now in front of everything.
  • Losing the client IP, then rate limiting every user as if they were one person.
  • Letting the gateway collect business logic until it is the riskiest deploy you have.
Say this
"One reverse proxy in front doing TLS, compression and rate limiting, so no service repeats that work. It is also the load balancer (same box), and I will run at least two of them, because it is now in front of everything."
5

The reverse proxies follow-up an interviewer will ask

"What is the difference between a reverse proxy and a load balancer?"

What a strong answer sounds like

Mostly framing, and the same software usually does both, which is worth saying instead of inventing a clean split. A load balancer exists to spread traffic across several identical servers, and it is meaningless with one server. A reverse proxy exists to be a front door: handling TLS, compressing, serving static files, applying rate limits, routing by path. That is useful even with a single backend. So the way I think about it is that load balancing is one feature a reverse proxy usually has. In a design I would draw one box and say what it does, rather than draw two boxes to satisfy a vocabulary question. And I would remember to run more than one of them, because whatever I call it, it is now in front of everything.

6

Your turn

60-second self-check

Name three things worth doing in a reverse proxy rather than in each service, and one thing that should not go there.

Stuck? Take one hint at a time0 of 2 used
0 / 25 characters
7

Learn it from the source

This page gets you interview-ready. These take you to where the idea is actually specified or measured — read them when you want the real depth.

Where you will use this