Featured image of post Reverse Proxies for  Performance and Scalability in Web Apps

Reverse Proxies for Performance and Scalability in Web Apps

Exploring How Reverse Proxies work

Phonebooth Stuffing:

Phonebooth Stuffing - Wikipedia

For a code example of visualizing Reverse Proxies see these articles:

Reverse Proxies Visually Explained
Reverse Proxies Scaling

Understanding How Reverse Proxies Improve Performance and Scalability in Web Applications

A Quick History of Proxy Servers

Proxy servers been around since the dawn of networked computers, acting as middlemen between clients and servers.

If you want the nitty-gritty details, check out Wikipedia’s proxy server history. But here’s the gist:

  • The earliest proxies were just gateways for passing requests between networks.
  • Forward proxies became popular to help clients access restricted content (hello, workplace YouTube restrictions).
  • Reverse proxies emerged to help websites handle massive amounts of traffic efficiently.

When Did Reverse Proxies Start Being Used?

Reverse proxies became a thing when websites started melting down under heavy traffic.

Some genius realized that instead of making one server handle everything, why not spread the load across multiple servers?

!!!BOOM!!!

Reverse proxies.

Now, before reverse proxies, people tried Round Robin DNS to distribute traffic.

This basically rotates requests among multiple IPs assigned to a domain. Sounds cool, right? Well, kinda. It has issues, like:

FeatureReverse ProxyRound Robin DNS
Load Balancing✅ Yes🚧 Limited
Failover Support✅ Yes❌ No
Caching✅ Yes❌ No
Security Features✅ Yes❌ No
SSL Termination✅ Yes❌ No

Reverse proxies win. DNS round robin is like a spinning wheel of fortune—you never know if the server you land on is dead or alive. 😅


Forward vs. Reverse Proxies

There are two main types of proxies:

  1. Forward Proxies – These are used by clients to access the internet. Think of it as an internet middleman for your browser.
  2. Reverse Proxies – These sit in front of web servers to handle incoming requests efficiently.

Reverse proxies do the heavy lifting for servers, handling:

  • Load balancing (spreading traffic across multiple servers)
  • Caching frequently requested content
  • SSL termination (handling HTTPS so your servers don’t have to)
  • Security filtering (blocking malicious traffic)

Setting Up a Reverse Proxy

Now let’s get our hands dirty. We’ll set up a reverse proxy using Nginx on both Windows and Linux.

Setting Up Nginx Reverse Proxy on Windows

  1. Download Nginx from the official site.
  2. Extract it somewhere (like C:\\nginx).
  3. Open conf/nginx.conf and add:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
server {
    listen 80;
    server_name mysite.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
  1. Run nginx.exe to start the server.

Setting Up Nginx Reverse Proxy on Linux

1
2
3
sudo apt update && sudo apt install nginx -y

sudo nano /etc/nginx/sites-available/reverse_proxy

Paste the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
server {
    listen 80;
    server_name mysite.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Then:

1
2
sudo ln -s /etc/nginx/sites-available/reverse_proxy /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Boom. You’re reverse proxying! 🚀


Reverse Proxies with Docker and Kubernetes

Using Nginx Reverse Proxy with Docker

Docker + Reverse Proxies = 💖. Here’s a simple docker-compose.yml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
version: '3'
services:
  app:
    image: myapp
    ports:
      - "3000:3000"

  nginx:
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "80:80"

Using Nginx Reverse Proxy in Kubernetes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
    - host: mysite.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 3000

Apply it:

1
kubectl apply -f ingress.yaml

Boom. K8s handles the rest. 🎉


Key Ideas Table

ConceptExplanation
Reverse ProxyA server that sits in front of web servers to improve performance, security, and scalability.
Load BalancingDistributes traffic across multiple servers to prevent overload.
CachingStores frequently accessed resources to improve response times.
SSL TerminationHandles HTTPS encryption so backend servers don’t have to.
Docker & KubernetesReverse proxies integrate well for managing containers and microservices.

References