System Design Fundamentals
Vote

0% completed

Introduction to API Gateway

API Gateway vs. Load Balancer

An API Gateway is a server-side architectural component that acts as an intermediary between clients and backend services.

Clients here means web browsers, mobile apps, or other services. Backend means your microservices and APIs.

Its main purpose is to provide a single entry point for external consumers to access the backend system. It receives a client request, forwards it to the appropriate microservice, and returns that service's response to the client.

Every client talks to one gateway, and the gateway talks to the individual microservices behind it
Every client talks to one gateway, and the gateway talks to the individual microservices behind it

Along the way it takes on jobs that would otherwise be repeated in every service: routing, authentication, rate limiting. That is the real benefit. Each microservice gets to focus on its own work, and the overall performance and scalability of the system improve because the shared concerns are handled in one place.

API Gateway vs. Load Balancer

These two get confused because both sit in front of your servers and both decide where a request goes. They decide different things.

An API gateway is focused on routing. It sends a request to the appropriate microservice.

A load balancer is focused on distributing. It spreads requests evenly across a group of backend servers.

The gateway reads the request and picks the right service, while the load balancer picks any healthy server from an identical pool
The gateway reads the request and picks the right service, while the load balancer picks any healthy server from an identical pool

The second difference is the kind of request each one handles.

An API gateway handles API requests. Those requests carry a specific URL that identifies which API the client is trying to reach, and the gateway routes to the appropriate microservice based on that URL.

A load balancer handles requests sent to a single, well-known IP address, and routes each one to one of many possible backend servers based on things like server performance and availability.

API GatewayLoad balancer
Focused onRoutingDistributing
Decides usingThe URL identifying the APIServer performance and availability
Behind it sitsDifferent services doing different jobsMany servers doing the same job
The question it answersWhich service should handle this?Which server is free?

Read the third row. That is the cleanest way to keep them apart. A load balancer chooses between machines that are interchangeable. A gateway chooses between services that are not.

💡 In an interview, put both in the picture rather than choosing between them. Real systems have a load balancer in front of the gateway, and often another one behind it, because the gateway itself runs as several instances and each microservice does too.

Key takeaway: An API Gateway is a server-side component that sits between clients and backend services and gives external consumers a single entry point. It routes each request to the appropriate microservice and handles shared concerns such as authentication and rate limiting, so services do not each implement them. A load balancer distributes requests evenly across interchangeable servers, while a gateway routes by the URL identifying the API to the service that owns it.

The next lesson, Usage of API Gateway, goes through what people actually put a gateway in front of their system to do.

Syed Mohammad Hassan

Syed Mohammad Hassan

· 4 months ago

My understanding is that:

A load balancer operates at the network level. Its only job is to distribute incoming traffic across multiple servers so no single server gets overwhelmed. It knows nothing about your API. it just sees "a request came in, which server should get it?" It uses strategies like round-robin, least-connections, or IP hashing.

An API gateway operates at the application level. It understands your API. It handles things like authentication/authorization, rate limiting, request routing to the correct microservice, SSL termination, request transformation, logging, and caching. Think of it as the "smart front door" for your API.

Show 1 reply
Sandeep Verma

Sandeep Verma

· 2 years ago

In some design there is gateway before API gateway . API gateway also has capability to load balance. What is recommended? .

Show 3 replies

On This Page

API Gateway vs. Load Balancer