A Reverse Proxy sits between clients and backend servers. Clients send requests to the reverse proxy, and the reverse proxy forwards those requests to the appropriate backend service.
flowchart LR
C["Client"] --> RP["Reverse Proxy"]
RP --> S1["Backend Server 1"]
RP --> S2["Backend Server 2"]
RP --> S3["Backend Server 3"]
1. Why Do We Need a Reverse Proxy?
- Hide backend servers from the internet
- Distribute traffic across multiple servers
- Terminate HTTPS
- Route requests
- Handle authentication/security policies
- Cache responses
- Compress responses
- Provide a single public endpoint
flowchart LR
U["Internet"] --> RP["Reverse Proxy"]
RP --> API1["API Server 1"]
RP --> API2["API Server 2"]
RP --> API3["API Server 3"]
API1 --> DB["Database"]
API2 --> DB
API3 --> DB
2. Reverse Proxy vs Forward Proxy
| Feature | Forward Proxy | Reverse Proxy |
|---|---|---|
| Represents | Client | Server |
| Hides | Client identity | Backend servers |
| Typical use | Corporate internet access | Web applications / APIs |
| Example | Corporate proxy | Nginx, HAProxy, ALB |
3. Reverse Proxy with Multiple Services
A reverse proxy can route requests based on hostname or URL path.
flowchart LR
C["Client"] --> RP["Reverse Proxy"]
RP -->|"/users"| U["User Service"]
RP -->|"/orders"| O["Order Service"]
RP -->|"/payments"| P["Payment Service"]
For example:
https://example.com/users
https://example.com/orders
https://example.com/payments
4. HTTPS Termination
The reverse proxy can handle TLS/HTTPS so backend services do not need to perform the public TLS termination themselves.
flowchart LR
C["Client"] -->|"HTTPS"| RP["Reverse Proxy"]
RP -->|"HTTP or HTTPS"| API["Backend API"]
This is called TLS termination.
5. Reverse Proxy as a Load Balancer
A reverse proxy can also distribute requests between multiple backend instances.
flowchart LR
C["Client"] --> RP["Reverse Proxy"]
RP --> A["API Instance 1"]
RP --> B["API Instance 2"]
RP --> D["API Instance 3"]
Therefore, a reverse proxy and load balancer can overlap in functionality, although they are not exactly the same concept.
6. Reverse Proxy vs Load Balancer
| Reverse Proxy | Load Balancer |
|---|---|
| Acts as intermediary for backend servers | Primarily distributes traffic |
| Can perform routing, TLS termination, caching | Can perform health checks and traffic distribution |
| Can route by URL/host | Can use algorithms such as Round Robin |
| Can also perform load balancing | May also behave as a reverse proxy |
7. Reverse Proxy in Microservices
In a microservices architecture, the reverse proxy provides a controlled entry point to backend services.
flowchart LR
C["Client"] --> RP["Reverse Proxy"]
RP --> A["Product Service"]
RP --> B["Order Service"]
RP --> C2["Payment Service"]
RP --> D["Notification Service"]
A --> DB["Databases"]
B --> DB
C2 --> DB
8. Popular Reverse Proxy Technologies
- Nginx
- HAProxy
- Apache HTTP Server
- Envoy
- Cloud load balancers such as AWS Application Load Balancer
9. Interview Scenario
Question: Your application has 10 backend servers. Should clients directly call those servers?
Usually, clients should call a single public endpoint. A reverse proxy can receive the request and forward it to an appropriate backend instance.
flowchart LR
C["Clients"] --> RP["Reverse Proxy"]
RP --> S1["Server 1"]
RP --> S2["Server 2"]
RP --> S3["Server 3"]
RP --> SN["Server 10"]
Important Interview Questions
- What is a reverse proxy?
- Why do we need a reverse proxy?
- Reverse proxy vs forward proxy?
- Reverse proxy vs load balancer?
- How does a reverse proxy hide backend servers?
- Can a reverse proxy perform load balancing?
- What is TLS termination?
- How can a reverse proxy route microservice requests?
- What are Nginx, HAProxy and Envoy used for?
Key Takeaways
- Reverse proxy sits between clients and backend servers.
- It hides backend infrastructure from clients.
- It can perform routing and TLS termination.
- It can distribute traffic across backend instances.
- It is commonly used in microservices architectures.
- Load balancers can also provide reverse-proxy functionality.
Conclusion
In system design interviews, remember the simple flow: Client → Reverse Proxy → Backend Services. The reverse proxy provides a single controlled entry point while handling routing, security, TLS termination and, when applicable, load balancing.