What is a Proxy?
A proxy server is an intermediary that sits between clients and servers, handling requests on behalf of one side or the other. The key distinction is whose side it's on: the client's side (forward proxy) or the server's side (reverse proxy).
Think of it like a translator or representative: they speak for you, but which "you"—the client or the server?
Forward Proxy (Client-Side Proxy)
A forward proxy sits between clients and the internet, acting on behalf of clients.
How It Works
- Client configures browser to use proxy
- Client sends request to proxy
- Proxy forwards request to destination server
- Server sees proxy's IP address, not client's
- Proxy returns response to client
Use Cases
1. Anonymity & Privacy
Client IP: 192.168.1.100 (hidden)
↓
Forward Proxy IP: 203.0.113.50
↓
Website sees: 203.0.113.50 (not your real IP)
Examples:
- HTTP or SOCKS proxies; a VPN is a different network-tunneling mechanism
- Tor network (onion routing through multiple proxies)
- Privacy-focused browsers
2. Access Control & Bypass Restrictions
# Pseudocode: an organization applies an outbound policy
if request.url.contains("facebook.com"):
return "403 Forbidden"
# But employees can use forward proxy outside network
employee → home proxy → facebook.com ✓
Examples:
- Bypass geographic restrictions (Netflix region locks)
- Access blocked websites in restrictive countries
- Circumvent corporate firewalls
3. Content Filtering (Corporate/School Networks)
# Squid proxy configuration (not Nginx syntax) acl blocked_sites dstdomain .facebook.com .youtube.com http_access deny blocked_sites
Examples:
- Schools blocking gaming sites
- Companies blocking streaming services
- Parental controls
4. Caching (Save Bandwidth)
100 employees request same software update Without proxy: 100 downloads × 500MB = 50GB bandwidth With proxy cache: 1 download × 500MB = 500MB bandwidth
Popular forward proxy software:
- Squid
- Apache HTTP Server (mod_proxy)
- SOCKS5 proxies
Reverse Proxy (Server-Side Proxy)
A reverse proxy sits in front of backend servers, acting on behalf of servers.
How It Works
- Client sends request to public-facing reverse proxy
- Proxy decides which backend server should handle it
- Proxy forwards request to chosen backend
- Backend processes request
- Proxy returns response to client
- Backend selection can be hidden, but headers, errors or application content can still reveal infrastructure
Use Cases
1. Load Balancing
Distribute traffic across multiple servers:
# Nginx reverse proxy config
upstream backend {
server backend1.example.com weight=3;
server backend2.example.com;
server backend3.example.com;
}
server {
location / {
proxy_pass http://backend;
}
}
Algorithms:
- Round Robin: Server1 → Server2 → Server3 → Server1...
- Least Connections: Send to server with fewest active connections
- IP Hash: Stable IP-based mapping while backend membership/configuration permits it
2. SSL/TLS Termination
Client ----HTTPS----> Reverse Proxy ----HTTP----> Backend Servers
(encrypted) (plain)
Benefits:
- Backend TLS is a separate decision; re-encrypt traffic when the trust boundary requires it
- Centralized certificate management
- Reduced CPU load on backend (no encryption overhead)
- Easier to implement HTTP/2 or HTTP/3
Example (Nginx):
server {
listen 443 ssl;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://backend:8080; # Plain HTTP to backend
}
}
3. Security & Hiding Backend
Attacker scans: reverse-proxy.com Finds: Nginx server Cannot see: Database at 10.0.0.5, App servers at 10.0.0.10-20
Security benefits:
- Hide backend server IPs and topology
- DDoS protection (Cloudflare, AWS Shield)
- WAF (Web Application Firewall) integration
- Rate limiting at proxy level
4. Caching Static Content
This configuration fragment belongs in Nginx’s http context, with the location inside a server. Cache only explicitly public responses; authenticated content needs a separate policy.
# http context:
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m
max_size=1g inactive=1d;
# server context:
# Cache eligible images, CSS and JS for up to 1 day
location ~* \.(jpg|jpeg|png|gif|css|js)$ {
proxy_pass http://backend;
proxy_cache my_cache;
proxy_cache_valid 200 1d;
add_header X-Cache-Status $upstream_cache_status;
}
Result:
- First request: Proxy fetches from backend, caches result
- Later eligible requests may be served from the cache
- The hit ratio depends on reuse, cache keys, TTL, eviction and cache-control rules
5. Compression
gzip on; gzip_types text/plain text/css application/json; proxy_pass http://backend;
Proxy compresses responses before sending to clients, saving bandwidth.
6. Routing & API Gateway
# Route based on URL path
location /api/users {
proxy_pass http://user-service:3000;
}
location /api/orders {
proxy_pass http://order-service:4000;
}
location /api/payments {
proxy_pass http://payment-service:5000;
}
Forward vs Reverse Proxy Comparison
| Aspect | Forward Proxy | Reverse Proxy |
|---|---|---|
| Acts on behalf of | Client | Server |
| Clients know about it? | Yes (must configure) | No (transparent) |
| Main purpose | Client privacy, filtering | Load balancing, security |
| Deployment | Client network/VPN | Server infrastructure |
| Can conceal | Client network address, depending on configuration | Backend addresses, depending on deployment |
| Examples | Squid, SOCKS proxies | Nginx, HAProxy, Cloudflare |
Visual Comparison
Forward Proxy Flow:
[Client] ---config---> [Forward Proxy] ---------> [Internet/Server]
(hides client)
Reverse Proxy Flow:
[Client] ---------> [Reverse Proxy] ---hidden---> [Backend Servers]
(public) (public-facing) (hidden)
Real-World Examples
Controlled outbound access
In a hypothetical office, a forward proxy provides one place to apply outbound allowlists and record approved access. It also becomes a trust and availability dependency. An address change alone does not guarantee anonymity: account logins, forwarded headers and browser identifiers remain relevant.
Cloudflare (Reverse Proxy)
yourwebsite.com points to Cloudflare IP (public) Cloudflare proxies requests to your origin server (hidden IP: 203.0.113.100) Benefits: - DDoS protection (Cloudflare absorbs attack) - Global CDN caching - SSL termination - Rate limiting - WAF rules
Nginx Reverse Proxy for Microservices
# docker-compose.yml
services:
nginx:
image: nginx
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
user-service:
image: user-api
ports:
- "3000:3000"
order-service:
image: order-api
ports:
- "4000:4000"
# nginx.conf
server {
location /users/ {
proxy_pass http://user-service:3000/;
}
location /orders/ {
proxy_pass http://order-service:4000/;
}
}
Proxy Technologies
Popular Reverse Proxies
| Technology | Strengths | Use Case |
|---|---|---|
| Nginx | High performance, low memory | Web servers, API gateway |
| HAProxy | Advanced load balancing | High-traffic sites |
| Traefik | Docker/Kubernetes native | Microservices |
| Cloudflare | Global CDN, DDoS protection | Public-facing sites |
| Envoy | Modern observability | Service mesh (Istio) |
Popular Forward Proxies
| Technology | Strengths | Use Case |
|---|---|---|
| Squid | Mature, full-featured | Corporate networks |
| Privoxy | Privacy-focused | Personal use |
| SOCKS5 | Protocol-agnostic | General proxying |
| Tor | Distributed onion routing with a defined threat model | Privacy-oriented connections |
Interview Tips 💡
When discussing proxies in system design interviews:
- Clarify which type: "Are we using a forward proxy for client privacy or reverse proxy for load balancing?"
- Explain the benefit: "A reverse proxy lets us hide backend servers and terminate SSL in one place..."
- Mention specific tools: "We'd use Nginx as a reverse proxy for load balancing and SSL termination..."
- Discuss caching: "The reverse proxy can cache static assets, reducing backend work in proportion to the measured cache-hit rate..."
- Security considerations: "A configured WAF integrated with a reverse proxy can reject selected malicious requests before they reach our application..."
- Scale implications: "With Cloudflare as reverse proxy, we can handle DDoS attacks and cache globally..."
Worked failure: one user sees another user’s page
A reverse proxy caches /account using only the URL as its key. User A’s personalized response is then served to user B. The proxy is working according to its configuration, but the cache policy is wrong. Keep private responses out of shared caches and test both authenticated and anonymous requests before enabling a broad file-extension or URL rule. Also define which proxies may set trusted forwarding headers; a client-supplied header is not proof of identity.
Nginx documents cache controls and forwarding behavior in its HTTP proxy module reference.
Related Concepts
- Load Balancing — Reverse proxies distribute load
- CDN — CDNs are specialized reverse proxies
- API Gateway — API gateways are reverse proxies with routing
- Caching — Proxies implement caching strategies
- Microservices — Reverse proxies route to services
Keep reading
Content Delivery Networks: Cache Keys, Freshness and Origin Load
Choose safe cache policies, calculate origin offload, and test personalized responses, invalidation and cold-cache recovery.
DNS Architecture
The phonebook of the internet. How Domain Name System works, the DNS hierarchy, and recursive vs iterative resolution strategies.
Service Discovery
A guide to microservice discovery in dynamic cloud environments, covering client-side vs server-side patterns, health checks, DNS-based discovery, and illustrative integrations using Consul, etcd, Eureka, and Kubernetes services.
BitTorrent: Pieces, Peer Discovery and Swarm Limits
Understand verified piece exchange, v1 versus v2 metadata, peer discovery, and the capacity limits of cooperative distribution.
GraphQL vs REST vs gRPC
Comprehensive comparison of three major API paradigms: REST (resource-based), GraphQL (query-based), and gRPC (RPC-based), covering performance, use cases, and implementation trade-offs for modern distributed systems.
HTTP Evolution (H1 to H3)
From text-based HTTP/1.1 to binary HTTP/2 and UDP-based HTTP/3 (QUIC). Why we needed upgrades and how they solve Head-of-Line Blocking.