1. What is a Reverse Proxy?

A Reverse Proxy is a server that sits in front of one or more backend servers.

Clients never communicate with the backend servers directly.

Instead:

Client
   │
   ▼
Reverse Proxy
   │
   ▼
Backend Server

The client thinks it's talking to the application, but it's actually talking to the reverse proxy first.

The reverse proxy receives the request and forwards it to the appropriate backend server.

Without Reverse Proxy

Client

↓

Backend Server

Every client directly accesses your application.

With Reverse Proxy

          Client
             │
             ▼
      Reverse Proxy
             │
             ▼
      Backend Server

The backend server may not even be exposed to the internet.

2. Why Use a Reverse Proxy?

A reverse proxy does much more than simply forward requests.

A. Hide Backend Servers

Instead of exposing:

203.0.113.10
203.0.113.11
203.0.113.12

Clients only know:

api.example.com

The backend infrastructure remains hidden.

B. SSL/TLS Termination

Imagine HTTPS requests.

Without a reverse proxy:

Client

↓

HTTPS

↓

Every backend server

Every backend server needs:

Instead:

Client

↓

HTTPS

↓

Reverse Proxy

↓

HTTP

↓

Backend Server

The reverse proxy handles TLS once and forwards the request internally (often over a trusted private network).

This reduces complexity because backend servers don't all need to manage certificates.

Note: In higher-security environments, traffic between the reverse proxy and backend servers may also use HTTPS/TLS.


C. Load Balancing

A reverse proxy can distribute traffic.

            Reverse Proxy
           /      |      \
          ▼       ▼       ▼
      Server1 Server2 Server3

This is exactly what we learned in the previous topic.

D. Caching

Suppose 10,000 users request:

/logo.png

Without caching:

10,000 requests

↓

Backend Server

With a reverse proxy:

First request

↓

Backend

↓

Cache

Every later request:

Reverse Proxy

↓

Cached Response

The backend doesn't need to generate or fetch the same response repeatedly.

E. Compression

Large responses can be compressed before being sent.

Example:

500 KB JSON

↓

Compression

↓

100 KB

This reduces bandwidth and can improve response times.

F. Security

A reverse proxy can:


3. What is Nginx?

Nginx (pronounced "Engine-X") is a high-performance web server that is also widely used as a:

One piece of software can perform several of these roles.

Example Architecture

             Internet
                 │
                 ▼
             Nginx
          /     |     \
         ▼      ▼      ▼
      Node1  Node2  Node3

Nginx receives every request.

It decides where to send it.

4. Why Backend Servers Use Reverse Proxies

Imagine a Node.js application.

Without Nginx:

Internet

↓

Node.js

Node.js now has to:

That's a lot of responsibilities.

Instead:

Internet

↓

Nginx

↓

Node.js

Now the responsibilities are divided.

Nginx handles:

Node.js handles:

Each component focuses on what it does best.

Reverse Proxy vs Load Balancer

Many people think they're the same, but they're not.

Reverse Proxy Load Balancer
Sits in front of backend servers Distributes requests across servers
Can forward to one or many servers Usually forwards to multiple servers
May cache, compress, terminate TLS, secure traffic Primarily focuses on distributing traffic efficiently

A reverse proxy can also act as a load balancer, which is why tools like Nginx are so popular.

Real-World Example

When you visit:

https://amazon.com

You are typically not connecting directly to an application server.

Instead, the request often follows a path like:

Browser

↓

Reverse Proxy / Load Balancer

↓

Application Servers

↓

Database

The browser only knows amazon.com; the internal server architecture is hidden behind the reverse proxy.

Interview Summary


Connection with Previous Topics

Client
   │
 HTTPS
   │
   ▼
Nginx (Reverse Proxy)
   │
 HTTP/HTTPS
   │
   ▼
Load Balancing
   ├────────► Backend Server 1
   ├────────► Backend Server 2
   └────────► Backend Server 3

This ties together everything you've studied so far: