We throw these terms around like they mean the same thing. But every time I draw a HLD I still pause at the box sitting between the client and my servers. What do I actually call it?
Reverse Proxy
A reverse proxy is a server that sits in front of your backend servers and handles client requests on their behalf.
A Reverse proxy can:
- Hide your backend - Your servers remain private. Only the reverse proxy is publicly exposed.
- Caching - It caches frequently requested payloads, images, etc.
- SSL Termination - It handles HTTPS encryption and decryption
- Firewall - Can enforce security rules (IP filtering, WAF-like behavior)
Load Balancer
A load balancer is just a specialised reverse proxy that mainly focuses on distributing requests evenly across multiple backend servers.
Common load balancing algorithms include:
- Round robin - Sends requests to each server in a cyclic fashion.
- Weighted round robin - Same as round robin but each server is assigned a weight that determines the ratio of requests it receives relative to the others.
- Least Connections - Sends requests to the server with the least number of active connections
- IP Hash - Hashes the client IP to choose a server. Makes sure requests from one client are served by the same server every time.
- Random - Chooses a server at random.
API Gateway
An API Gateway is also a specialised reverse proxy that serves as a single entry point for all API requests.
In addition to basic proxying, it also handles:
- Authentication and Authorisation
- Rate limiting
- Request/Response transformation
- Monitoring and Analytics