Understanding Gateway, Load Balancer, Forward Proxy, and Reverse Proxy

Anish RatnawatAnish Ratnawat
3 min read

Gateway

A gateway acts as a single entry point into a system. It is commonly used in microservices architectures to route client requests to appropriate backend services. Gateways often incorporate additional functionalities like:

  • Authentication and Authorization: Ensuring only authorized users access certain resources.

  • Protocol Translation: Converting protocols like HTTP to WebSocket or gRPC.

  • Request Aggregation: Combining responses from multiple services into a single response.

  • Service Discovery: process of finding and locating available service instances within a distributed system.

  • Rate Limiting: technique that limits the number of requests an API can handle in a given time frame.

  • SSL Termination: process of decrypting encrypted traffic before passing it along to a web server.

Popular Tools:

  • API Gateway: Tools like Kong, Apigee, or AWS API Gateway manage APIs by abstracting backend services and enforcing policies.

  • Service Gateway: Tools like Istio function within service meshes, facilitating inter-service communication and applying policies.


Load Balancer

A load balancer distributes incoming network traffic across multiple servers to ensure high availability and reliability. It helps achieve fault tolerance, scalability, and optimal resource utilization.

Types of Load Balancers:

  1. Layer 4 Load Balancers: Operate at the transport layer (TCP/UDP) and use information like IP address and port for routing.

    • Example: AWS Elastic Load Balancer (Classic).
  2. Layer 7 Load Balancers: Operate at the application layer, making routing decisions based on HTTP headers, URLs, and other application-level data.

    • Example: NGINX, HAProxy.

Load Balancing Algorithms:

  • Round Robin: Requests are distributed sequentially across servers.

  • Least Connections: Routes to the server with the fewest active connections.

  • IP Hash: Routes based on client IP, ensuring session persistence.


Gateway vs Load Balancers

There are two scenarios to consider here to clarify the confusion. I have clarified this using microservices example as this would make sense there only.

Scenario 1: You have a cluster of API Gateways

User ---> Load Balancer (provided by Cloud Providers like AWS or your own) ---> API Gateway Cluster ---> Service Discovery Agent (like eureka) ---> Microservice A ---> Client Side Load Balancer ---> Microservice B

Scenario 2: You have a single API Gateway

User ---> API Gateway ---> Service Discovery Agent (like Eureka) ---> Microservice A ---> Client Side Load Balancer -> Microservice B

I hope you understand why we required Load Balancer before the API Gateway in Scenario 1, as there we had multiple instances of API gateway also to handle the large traffic and to avoid the burden on the single api gateway since gateway itself can have several task to manage as per the requirements, so to distribute the load among them, we have load balancer.


Forward Proxy

A forward proxy Forward proxy acts as a request server that hides client identify and execute client request on behalf on client hiding client IP.. It is typically used for:

  • Caching: Storing frequently accessed data to reduce latency.

  • Anonymity: Masking the client's identity.

  • Content Filtering: Blocking access to certain websites.

Use Case Example: An organization might use a forward proxy to allow employees to access the internet while restricting access to non-work-related sites.


Reverse Proxy

A reverse proxy operates on behalf of servers, handling requests from clients and forwarding them to appropriate backend servers. Common functionalities include:

  • Load Balancing: Distributing traffic among servers.

  • SSL Termination: Offloading SSL decryption to reduce server load.

  • Caching: Storing responses to reduce server load and latency for repeated requests.

  • Security: Hiding backend server details and blocking malicious traffic.

Popular Tools: NGINX, Apache HTTP Server, Traefik.

Use Case Example: A reverse proxy can sit in front of an application server, handling SSL termination, caching, and load balancing.

0
Subscribe to my newsletter

Read articles from Anish Ratnawat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anish Ratnawat
Anish Ratnawat