Proxy & Reverse Proxy
A middle server between a client and the real destination, working for one side or the other.
What is it?
Sometimes a request passes through a middle server before reaching the server that handles it.
- A forward proxy sits in front of clients and sends their requests out for them, often hiding who the client is or filtering what they can reach.
- A reverse proxy sits in front of servers and passes incoming requests to the right backend, often hiding how many servers there are or what they look like.
Same idea (a middle server relaying requests), opposite problems.
Explain like I'm 10
A forward proxy is like an assistant who makes calls for you, so the other person never sees your number. A reverse proxy is like a company's reception desk: every visitor talks to the same receptionist, who sends them to the right employee, so visitors never need to know who works where.
Examples
A reverse proxy routing to different backends
// Simplified reverse proxy config
routes: {
"/api/*": "backend-server:4000",
"/images/*": "image-server:5000",
"/*": "web-server:3000",
}
// A request to /api/users is forwarded to backend-server,
// while a request to /home.html goes to web-server —
// the client only ever talks to one address.How it works
A reverse proxy receives every incoming request first and looks at it (usually just the path or domain). It forwards the request to the backend responsible for it, then relays the response back as if it came from the proxy.
A forward proxy is the mirror image. It sits in front of clients, takes their outgoing requests, and sends them on, often changing or hiding details of the original request.
Why does it exist?
Without a reverse proxy, clients would need the exact address of every backend service, and each service would be exposed to the internet. A reverse proxy gives clients one stable address, while the number and role of servers behind it stay hidden and free to change.
When to use it
Use a reverse proxy when you have more than one backend service (or more than one instance of a service) and want one stable entry point. A load balancer is exactly this: a reverse proxy that spreads traffic across identical servers.
Use a forward proxy when clients' outgoing requests need filtering, caching, or their identity hidden.
When not to use it
For a single simple server with nothing to route between, a reverse proxy adds an extra network hop with no real benefit yet. You can add one later as the system grows.
Common mistakes
Confusing a forward proxy (works for clients) with a reverse proxy (works for servers). They solve different problems.
Forgetting the reverse proxy itself must stay up. If it goes down, so does access to everything behind it.
Exposing backend addresses directly instead of routing everything through the proxy, which defeats hiding the internal architecture.
Practice exercises
- Easy:
Explain in your own words the difference between a forward proxy and a reverse proxy.
- Medium:
Sketch (in words) a reverse proxy config that routes /api requests to one server and everything else to another.
- Hard:
Explain how a load balancer and a reverse proxy relate. Is a load balancer a kind of reverse proxy, or something separate?
Interview questions
What's the difference between a forward proxy and a reverse proxy?
A forward proxy sits in front of clients and sends their outgoing requests for them. A reverse proxy sits in front of servers and passes incoming requests to the right backend.
Why would you put a reverse proxy in front of multiple backend servers?
Clients need only one address, and the proxy routes each request to the right backend. The internal setup stays hidden and easy to change.
Is a load balancer a type of reverse proxy?
Effectively yes: it's a reverse proxy whose job is spreading traffic across identical backend servers.
What are common reasons an organization deploys a forward proxy for its own employees?
To block certain sites, cache popular content to save bandwidth, log outbound traffic for compliance, and hide internal IP addresses from the sites employees visit.
How does a reverse proxy help with SSL/TLS termination?
The proxy decrypts incoming HTTPS (and encrypts responses) in one place, so backends don't each manage certificates and TLS handshakes. That simplifies certificate management and takes the CPU cost off the app servers.
Why might a reverse proxy cache static content before it even reaches the application server?
Rarely changing content (images, CSS, JS bundles) can be served from the proxy's cache, which is much faster than running backend logic for the same response every time.
What single point of failure risk does adding a reverse proxy introduce, and how is it usually mitigated?
With only one proxy, its failure cuts off everything behind it even if backends are fine. The fix is several redundant proxies behind something like DNS round-robin or a floating IP.
How does a reverse proxy enable zero-downtime deployments?
Start the new version alongside the old one, and have the proxy gradually shift traffic to it and away from the old one. Clients never see an interruption, unlike replacing a single exposed server in place.
What's the difference between a reverse proxy and an API gateway?
A reverse proxy routes requests to the right backend. An API gateway adds API concerns on top: authentication, rate limiting, request/response transformation, and combining several backend calls into one response.
How does a CDN relate to the concept of a reverse proxy?
A CDN is a globally distributed reverse proxy. It sits in front of an origin server at many edge locations and caches and serves content from the one closest to the client.
Why does a reverse proxy typically add headers like X-Forwarded-For to the requests it forwards?
Behind a proxy, the backend sees only the proxy's IP as the source. X-Forwarded-For keeps the original client's IP so the backend can still log, rate-limit, or geolocate by the real client.
What problem does the X-Forwarded-For header solve?
Losing the original client's IP after a request passes through one or more proxies. Without it, the backend sees only the last proxy in the chain as the source of every request.
How can a reverse proxy implement rate limiting across an entire fleet of backend servers?
Every request passes through the proxy first, so it can count requests per client (by IP, API key, etc.) in one place and reject or throttle over the limit. Backends don't need to track and share counts themselves.
Describe a scenario where a system would use both a forward proxy and a reverse proxy at once.
A company's staff reach the internet through a forward proxy (filtering and logging outbound traffic), while requests to the company's public service go through a separate reverse proxy to the right internal backend. The two handle opposite directions of traffic.
Why might a company route its clients' outbound connections through a forward proxy for security reasons?
It gives one choke point to inspect, filter, or block risky outbound connections (like known-malicious domains), instead of relying on every machine to enforce the policy.
What's a potential downside of routing all traffic through a single reverse proxy layer?
Every request gets an extra network hop and a little latency. If it isn't scaled or made redundant, it can become a bottleneck or outage point for the whole system even when backends are healthy.
How does a reverse proxy decouple clients from changes in backend infrastructure?
Clients only use the proxy's stable public endpoint. Backends can be added, removed, resized, or moved without clients changing anything; only the proxy's routing needs updating.
Why is it important for a reverse proxy itself to be highly available?
Every request passes through it, so if it goes down, every backend behind it is unreachable. Its availability caps the availability of the whole system.