What is a reverse proxy?
A reverse proxy sits between a client and a web server by handling the request and response on behalf of the server. It intercepts requests from the client and forwards them to the appropriate backend server and sends the corresponding responses back to the client. It can also provide additional features such as load balancing, caching, and security.
The way reverse proxies work can be thought of as the following sequence of steps that detail what happens from the initial request from a client to the final response from a web server that goes through a reverse proxy:
- The client initially sends a request to a web server. Unknown to the client, this request instead is intercepted by the reverse proxy as it's acting on behalf of the server.
- The reverse proxy checks the request to determine where to forward the request. It may use load-balancing algorithms to determine which server to send the request to.
- The reverse proxy forwards the request to the appropriate server.
- The server processes the request and generates a response and sends the response back to the reverse proxy.
- The reverse proxy receives the response and can optionally perform additional processing such as caching, filtering, or modifying the response.
- The reverse proxy sends the response back to the client as if it came from the original server.

Common use cases of a reverse proxy
- Load balancing: A reverse proxy can distribute incoming traffic across multiple backend servers to improve the performance, availability, and scalability of the application.
- SSL/TLS termination: A reverse proxy can handle SSL/TLS encryption and decryption on behalf of the backend web server
- Compression: A reverse proxy can compress the content being transmitted, reducing the bandwidth required and improving performance.
- Caching: A reverse proxy can cache frequently accessed content to reduce the load on the backend servers which leads to an improvement in response times.
- Security: A reverse proxy can provide an additional layer of security by filtering and blocking malicious traffic, limiting access to certain resources, and enforcing authentication and authorization policies.
API gateway vs reverse proxy
Both API gateways and reverse proxies have overlapping features, but they both serve different purposes. While the API gateway acts like the front door to your underlying APIs, a reverse proxy is the front door to your web applications.
When it comes to functionality, API gateways are tailored for API management, and hence the functionality they offer are:
- API versioning and transformation
- Authentication and authorization (e.g., OAuth, JWT, and other api authentication types)
- Rate limiting and throttling
- Caching
- Logging and API monitoring
- Request/response transformation
- Service discovery
- Circuit breaker and fault tolerance
Reverse proxies, on the other hand, offer a more generalized feature set that can be applied to any type of web service be it an API or a web server. The functionality includes things like:
- Load balancing
- SSL offloading/termination
- Caching
- Compression
- URL rewriting
- Security features (e.g., filtering malicious requests, handling DDoS attacks)
In terms of setting up and configuration, API gateways often require more setup and maintenance than a reverse proxy due to a more extensive feature set. To get an API gateway up and running, you generally need to define routes to your underlying APIs, set up authentication, and configure other API-related policies. A reverse proxy on the other hand can be set up in a much simpler way.
Advantages of an API gateway over a reverse proxy
API gateways provide more advanced features compared to a reverse proxy especially when it comes to the management of APIs. Some of the key benefits include:
- Developer experience: API gateways often provide a much better experience to both internal and external developers that enhances the use of the underlying APIs. These features could include a developer portal, registration facility, and mock responses.
- API-specific advanced features: An API gateway provides advanced features for managing the full lifecycle of an API. Some of the features that aren't available in reverse proxies include:
- API lifecycle management including version control
- Authentication/authorization, including integration with existing IDP systems
- Rate limiting or throttling based on tiers
- Simple transformation in request/response
- Centralized API management: Although reverse proxies and API gateways both may act as a single point for access to your APIs, when it comes to managing and controlling all your APIs consistently, API gateways provide a much greater level of control. They make it easier to enforce policies, monitor usage, and maintain consistency across all the different services.
Conclusion
The key to choosing between an API gateway, API proxy, or a reverse proxy is to look at the underlying use case:
If the primary goal is to manage multiple APIs in a standardized way with full lifecycle management and enhanced developer experience, then you need all the advanced features that an API gateway provides. However, if you're looking for a general-purpose solution for handling web traffic, then a reverse proxy might be more appropriate.
Continued Learning and Related Content