📌 Reverse Proxy vs Load Balancer vs API Gateway
Core Idea:
All 3 sit between Client ↔ Server, but each solves a different infrastructure problem.
⚡ Quick Responsibility (Interview Revision)
Reverse Proxy
| Feature | Purpose |
|---|---|
| SSL Termination | Remove encryption overhead |
| Caching | Serve repeated responses |
| Compression | Reduce payload size |
| Security | Hide backend + filter attacks |
| Routing | Forward requests |
Load Balancer
| Feature | Purpose |
|---|---|
| Traffic Distribution | Spread requests |
| Health Checks | Detect failures |
| Failover | Skip unhealthy servers |
| Horizontal Scaling (ASG) | Add more machines |
API Gateway
| Feature | Purpose |
|---|---|
| Authentication | JWT / API keys |
| Authorization | Access control |
| Rate Limiting | Protect APIs |
| Versioning | /v1, /v2 |
| Transformation | JSON ↔ XML |
| Analytics | API metrics |
🏗️ How They Work Together (Real Architecture)
User
↓
CDN → Global delivery
↓
API Gateway → API policies
↓
Load Balancer → Traffic distribution
↓
Service Instances
↓
Reverse Proxy → Optimization & protection
↓
Application🎯 Decision Rule
Need SSL / Cache / Security?
→ Reverse Proxy
Need Multiple Servers?
→ Load Balancer
Need Auth / Rate Limiting / Public APIs?
→ API Gateway1️⃣ Reverse Proxy → Protect + Optimize Servers
What is it?
A server-side proxy that sits in front of backend servers.
Client
↓
Reverse Proxy
↓
BackendUsers never directly access backend servers.
Why Do We Need It?
Backend servers should focus only on business logic.
Move infrastructure concerns outside:
- SSL termination
- Caching
- Compression
- Security filtering
- Static file serving
Responsibilities
| Feature | Purpose |
|---|---|
| SSL Termination | Remove encryption overhead |
| Caching | Serve repeated responses |
| Compression | Reduce payload size |
| Security | Hide backend + filter attacks |
| Routing | Forward requests |
Example Flow
User
↓
Reverse Proxy (NGINX)
↓
Application ServerPopular Tools
2️⃣ Load Balancer → Scale + High Availability
What is it?
A specialized reverse proxy that distributes traffic across multiple servers.
Client
↓
Load Balancer
↓
Multiple ServersWhy Do We Need It?
A single server eventually hits limits:
- CPU
- Memory
- Network connections Solution:
Add more servers
↓
Distribute trafficResponsibilities
| Feature | Purpose |
|---|---|
| Traffic Distribution | Spread requests |
| Health Checks | Detect failures |
| Failover | Skip unhealthy servers |
| Horizontal Scaling | Add more machines |
Common Algorithms
Round Robin
Req1 → A
Req2 → B
Req3 → CLeast Connections
Send traffic to least busy serverWeighted Routing
Powerful servers → Receive more trafficIP Hash
Same user → Same serverLayer 4 vs Layer 7
| Layer 4 (NLB) | Layer 7 (ALB) |
|---|---|
| TCP/IP | HTTP |
| Faster | Smarter |
| No URL awareness | Reads URL & Headers |
Examples:
- Layer 4 → TCP balancing
- Layer 7 →
/users→ Cluster A
Popular Tools
3️⃣ API Gateway → Manage APIs
What is it?
An API-aware reverse proxy.
Client
↓
API Gateway
↓
MicroservicesWhy Do We Need It?
Microservices duplicate infrastructure logic:
- Authentication
- Rate limiting
- Monitoring
- Transformation
Centralize everything.
Responsibilities
| Feature | Purpose |
|---|---|
| Authentication | JWT / API keys |
| Authorization | Access control |
| Rate Limiting | Protect APIs |
| Versioning | /v1, /v2 |
| Transformation | JSON ↔ XML |
| Analytics | API metrics |
Example
/api/users
↓
API Gateway
↓
User ServicePopular Tools
📊 Comparison Table
| Feature | Reverse Proxy | Load Balancer | API Gateway |
|---|---|---|---|
| Main Goal | Protect | Scale | Manage APIs |
| Multiple Servers | Optional | Yes | Usually |
| SSL | ✅ | ✅ | ✅ |
| Caching | ✅ | Sometimes | Sometimes |
| Health Check | ❌ | ✅ | ✅ |
| Traffic Distribution | Basic | Advanced | API-based |
| Authentication | ❌ | ❌ | ✅ |
| Rate Limiting | ❌ | ❌ | ✅ |
| Versioning | ❌ | ❌ | ✅ |