Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 28

Understanding Reverse Proxies: Roles and Use Cases

Recommended resources

Hello! Welcome to the first lesson in our new module, "Core Infrastructure Components."

In our previous module, we concluded by exploring idempotency, a crucial pattern for ensuring reliability in distributed systems. We saw that components like API Gateways are natural places to implement such cross-cutting concerns. This brings us to the foundational elements that make up a modern distributed architecture.

Today, we'll start with one of the most fundamental of these components. Your learning outcome is to explain the role of reverse proxies and when to use them. Understanding the reverse proxy is non-negotiable for a senior engineering interview. It’s a building block for scalability, security, and reliability, and being able to clearly articulate its purpose and trade-offs is a strong signal of architectural maturity.

1. What is a Reverse Proxy?

At its core, a reverse proxy is an intermediary server that sits between external clients (like users on the internet) and your backend servers. Instead of clients communicating directly with your application servers, they communicate with the reverse proxy, which then forwards the request to the appropriate backend server.

To the client, the reverse proxy appears to be the origin server. This simple act of intermediation is incredibly powerful. Let's start with a short video for a quick visual overview.

Proxy vs Reverse Proxy (Real-world Examples)

The channel ByteByteGo is well-regarded for its clear system design visuals. This video provides a concise introduction to the concept of a reverse proxy.

Please watch from 02:21 to 02:34. This short clip will give you the essential definition of where a reverse proxy sits in an architecture.

Distinguishing Forward vs. Reverse Proxies

A common point of confusion is the difference between a "forward proxy" and a "reverse proxy." The distinction lies in whose behalf the proxy is acting:

  • A Forward Proxy acts on behalf of the client. It's used by clients (e.g., within a corporate network) to access the internet. It hides the client's identity from the external servers.
  • A Reverse Proxy acts on behalf of the server. It's used by servers to accept traffic from the internet. It hides the server's identity from the external clients.

This image provides a clear visual distinction.

Forward Proxy vs. Reverse Proxy Diagram
This diagram shows that a forward proxy sits in front of clients, managing outgoing requests, while a reverse proxy sits in front of servers, managing incoming requests. For system design interviews, our focus is almost always on the reverse proxy.

2. The Core Roles of a Reverse Proxy

A reverse proxy is more than just a simple request forwarder. It serves as a strategic control point for handling incoming traffic, enabling several key architectural patterns. As a backend engineer, you've certainly benefited from these capabilities, whether they were provided by Nginx, HAProxy, or a cloud provider's load balancer.

The following video walks through the primary functions of a reverse proxy.

Understanding Proxy, Forward Proxy, and Reverse Proxy

This video by Arpit Bhayani provides an excellent breakdown of the key responsibilities a reverse proxy can take on. We'll watch it in segments to focus on each role.

Please watch from 04:35 to 06:43. As you watch, focus on how the reverse proxy provides the following four benefits: Load Balancing: Distributing requests across multiple backend servers. Routing: Directing requests based on URL paths. Caching: Serving stored responses for common requests. Abstraction: Hiding the complexity and dynamic nature of the backend infrastructure.

Let's solidify these key roles, which you should be prepared to discuss in an interview:

  • Load Balancing: This is one of the most common uses. By distributing incoming traffic across a pool of identical backend servers, a reverse proxy prevents any single server from becoming a bottleneck. This is fundamental to achieving horizontal scalability and high availability.

  • Security Shielding: The reverse proxy acts as a "front door," hiding the IP addresses and network topology of your backend servers. This makes it significantly harder for attackers to target your application servers directly (e.g., with DDoS attacks). It provides a single point to enforce security policies.

  • SSL/TLS Termination: Decrypting HTTPS traffic is computationally expensive. A reverse proxy can terminate the SSL/TLS connection, decrypt the request, and then forward it to backend servers over a faster, unencrypted internal network. This offloads the cryptographic work from your application servers, allowing them to focus on business logic.

  • Caching: A reverse proxy can cache static assets (like images, CSS, JavaScript) and even frequently accessed API responses. When a subsequent request for the same resource arrives, the proxy can serve it directly from its cache, reducing latency for the user and decreasing the load on your backend.

  • Request Routing & URL Rewriting: In a microservices architecture, a reverse proxy can route requests to different services based on the URL path (e.g., /api/users goes to the User Service, /api/orders goes to the Order Service). It can also rewrite URLs to present a clean, consistent API to the outside world while hiding the internal service layout.

  • Compression: It can compress outgoing responses (e.g., using gzip) before sending them to the client, reducing bandwidth costs and speeding up transfer times.


3. When to Use a Reverse Proxy (and When to Use Something Else)

For a senior role, simply listing the functions of a reverse proxy isn't enough. You need to articulate why and when you would choose it over similar components, like a dedicated Load Balancer or an API Gateway. The lines between these are often blurry because they have overlapping features.

A great mental model for interviews is to focus on the primary responsibility of each component.

API Gateway vs Load Balancer vs Reverse Proxy

This article from Level-Up Coding provides a sharp, clear framework for distinguishing between these three edge components. It's an excellent resource for structuring your interview answers.

Please read the sections 'The One Decision Each Component Makes', 'Reverse Proxy: "Front the servers..."', and 'Choosing the Right Tool'. Focus on the core verbs the author uses to differentiate the components: distribute (Load Balancer), forward + optimize (Reverse Proxy), and govern (API Gateway).

Let's summarize the decision-making process:

Reverse Proxy vs API Gateway vs Load Balancer Comparison
This visual reinforces the distinct primary roles. A Load Balancer distributes to identical services. A Reverse Proxy fronts one or more services, often adding optimizations. An API Gateway governs access to many different services with business-level policies.
  • Use a Load Balancer when... your primary goal is to distribute traffic evenly across multiple identical instances of a service for scalability and high availability. While many reverse proxies can load balance, a dedicated hardware or cloud load balancer (like an L4 load balancer) might be simpler and faster if distribution is your only need.

  • Use a Reverse Proxy when... your goal is to forward and optimize. You need a single entry point to one or more backend services and want to add capabilities like caching, SSL termination, or basic path-based routing. Nginx and HAProxy are classic examples of software used as powerful reverse proxies.

  • Use an API Gateway when... your goal is to govern a complex ecosystem of microservices. An API Gateway is a specialized reverse proxy that adds advanced API-centric features like authentication/authorization, rate limiting, request/response transformation, and detailed monitoring/analytics.

In practice, large systems often layer these components. You might have a cloud load balancer at the edge, which directs traffic to an API Gateway, which in turn routes requests to backend services that might themselves be behind another internal reverse proxy for caching. The key is that each component has a clear, defined responsibility.


Conclusion

You have now explored the role of a reverse proxy, a versatile and essential component in modern system architecture. Being able to explain its functions and differentiate it from related components demonstrates a solid grasp of backend infrastructure.

Key Takeaways:

  • A reverse proxy is an intermediary server that sits in front of backend servers, acting on their behalf to handle client requests.
  • Its core roles include load balancing, security shielding, SSL termination, caching, request routing, and compression.
  • The choice between a reverse proxy, load balancer, and API gateway depends on the primary problem you're solving:
    • Load Balancer → Distribute
    • Reverse Proxy → Forward & Optimize
    • API Gateway → Govern

Next Lesson Preview:

We've seen how a reverse proxy can route traffic to different services. But in a dynamic microservices environment where services are constantly being deployed, scaled, and moved, how does the reverse proxy know the current network locations (IP addresses and ports) of the services it needs to route to? Manually updating a config file isn't scalable. This is the problem that service discovery solves. In our next lesson, we'll dive into common service discovery patterns.