Proxy
A proxy is a server that sits in the middle of a connection and handles requests on behalf of someone else. Instead of two parties talking directly, one party talks to the proxy, and the proxy talks to the other party. The difference between a forward proxy and a reverse proxy is simply whose side the proxy is on. A forward proxy acts for the clients, and a reverse proxy acts for the servers. The easiest way to remember it is that a forward proxy hides the client from the internet, while a reverse proxy hides the servers from the internet.
Forward Proxy¶
A forward proxy sits between the clients and the internet. Users inside a network, such as a company, school or home, send their requests to the proxy instead of directly to websites. The proxy then makes the request to the destination on their behalf and passes the response back. The client has to be configured to use it, either manually in the browser or system settings or through network rules set by an administrator.
Because every request passes through it, the forward proxy gives the network owner a single point of control. It can enforce access control by deciding which users may reach the internet at all, filter content by blocking categories of websites such as social media or malware domains, and log all activity for auditing. It also provides privacy and protection for the client. The websites being visited only see the IP address of the proxy and never the real IP address of the user's machine, so the actual client is not exposed.
A forward proxy can also cache. If many users in the same network request the same page or file, the proxy fetches it from the internet once and serves the stored copy to everyone else, which saves bandwidth and makes access faster for the clients. A VPN is the common example people know, since it also makes websites see a different IP address than your own. A VPN and a proxy are not exactly the same though. A proxy usually handles traffic for specific applications such as a browser, while a VPN creates an encrypted tunnel for all traffic from the device at the network level.
Reverse Proxy¶
A reverse proxy sits in front of one or more servers, between the internet and the company's private network. Clients on the internet send requests to the reverse proxy believing it is the actual server, and the proxy forwards each request to the right backend server and returns the response. Unlike a forward proxy, clients do not need any special configuration, and they are usually unaware that a proxy exists at all. NGINX, HAProxy and cloud gateways are the usual examples.
The main benefit is protection of the servers. Backend servers receive traffic only from the reverse proxy, so their private IP addresses and internal structure are never visible to the outside world. An attacker can only reach the proxy, which can filter malicious requests, rate limit abusive clients and work with a web application firewall to block known attack patterns, before anything touches the application servers.
A reverse proxy is also a very useful place to put shared functionality so that each backend server does not have to implement it separately. It handles SSL/TLS termination, meaning it manages the certificates and does the encryption and decryption work, so backend servers can communicate in plain traffic over the private network. It can cache responses and serve repeated requests without bothering the backend, compress responses before sending them, and route requests to different backend services based on the URL path or headers, which is how a single public address can front many internal services.
Most importantly for system design, a reverse proxy is where load balancing happens. A load balancer that works at the application layer is a reverse proxy that has several backend servers and chooses between them using an algorithm such as round robin or least connections. This is why the two terms are so closely linked. A reverse proxy in front of a single server provides security, caching and SSL termination without balancing anything, while a reverse proxy in front of many servers is also acting as a load balancer.
One practical detail is that the backend servers see the proxy's IP address as the source of every request, not the real client's. To keep the original address available for logging and security rules, the proxy adds a header, most commonly X-Forwarded-For, containing the real client IP.