Dev tools

API Gateway vs Load Balancer: What Each One Does

API gateway vs load balancer: one manages and secures API calls, the other spreads traffic across servers. See how they differ and work together.

By OmniAI Editorial · Nov 22, 2026 · 13 min read

In API gateway vs load balancer, the short answer is that they solve different problems and are usually used together. A load balancer spreads incoming traffic across several copies of the same server so that none is overloaded and a failed one is skipped. An API gateway is the single front door to your APIs: it knows what each request is asking for, checks who is calling, enforces limits and sends the request to the right service. One is about capacity and availability; the other is about API management and control.

This guide explains the difference between API gateway and load balancer in plain terms: what each does, where each sits in the request path, a table of the key differences, a worked request flow, which comes first, how to choose, and the mistakes that make people buy one when they needed the other. The examples use AWS terms because its documentation is public and precise, but the ideas apply to any cloud or to self-hosted tools.

API Gateway vs Load Balancer at a Glance

Load balancerAPI gateway
Main jobDistribute traffic across serversManage, secure and route API calls
Typical layerLayer 4 (TCP/UDP) or layer 7 (HTTP)Layer 7 (application)
Knows about APIs?Only enough to route (paths, hosts, headers)Yes: endpoints, versions, clients, plans
AuthenticationLimited (some can authenticate users)Core feature: API keys, tokens, OAuth checks
Rate limiting and quotasNot its jobCore feature
Request and response changesRareCommon: transform, validate, add headers
Service discovery and routingTargets in a groupRoutes to different back-end services per path
Health checksCore featureOften delegated to the load balancer behind it
ScalesVery high connection and request volumeDepends on policy work per request
Cost modelHours plus capacityOften per request plus data

If you remember one thing: the load balancer answers "which server?", and the API gateway answers "may this caller do this, and which service handles it?".

What Is a Load Balancer?

A load balancer sits in front of a group of identical servers and shares requests among them. AWS's documentation describes it as distributing traffic across multiple targets in one or more availability zones, monitoring their health and routing traffic only to healthy ones. That gives two benefits: scalability (add servers to handle more traffic) and availability (if one server fails, the others carry on).

Load balancers come in two main flavours:

  • Layer 4 (network) load balancers work with TCP and UDP connections. They look at IP addresses and ports and don't read the content. AWS's Network Load Balancer works at layer 4 and handles millions of requests per second. It's the right tool for raw performance or for non-HTTP protocols.
  • Layer 7 (application) load balancers understand HTTP. AWS's Application Load Balancer works at the seventh layer and evaluates listener rules in priority order, routing by path, host name, headers, methods or query parameters. The default routing algorithm is round robin, with "least outstanding requests" as an alternative. It can terminate TLS (decrypt traffic so the servers don't have to), redirect, return fixed responses and authenticate users through an identity provider.

Whatever the layer, a load balancer's core features are the same: a pool of targets, health checks, a balancing algorithm and, in the cloud, automatic scaling of its own capacity. The common algorithms:

AlgorithmHow it picks a serverGood for
Round robinTakes turns in orderSimilar servers and similar requests
Least connectionsServer with the fewest active connectionsRequests of uneven length
IP hashSame client address goes to the same serverSimple session stickiness
WeightedMore traffic to bigger serversMixed hardware

In NGINX, for example, round robin is the default, and a pool is just an upstream block:

upstream backend {
    server backend1.example.com weight=5;
    server backend2.example.com;
    server 192.0.0.1 backup;
}

server {
    location / {
        proxy_pass http://backend;
    }
}

The first server gets five times the traffic of the second (default weight is 1), and the backup server is used only when the others are unavailable. Our comparison of NGINX vs Caddy shows how two popular servers handle this.

What Is an API Gateway?

What is an API gateway? It's a service that acts as the single entry point for clients calling your APIs, usually placed in front of several back-end services or microservices. Instead of every client knowing the address of every service, clients call the gateway, and the gateway applies rules and forwards the request.

The standard jobs of an API gateway:

  • Routing. /orders/* goes to the orders service, /users/* to the users service, and different API versions can go to different back ends.
  • Authentication and authorisation. Check API keys, JSON Web Tokens or OAuth tokens once at the edge, so each service doesn't have to.
  • Rate limiting and quotas. Protect services from overload and enforce plans per client. Our guide to API rate limiting covers the algorithms.
  • Request and response handling. Validate input, transform formats, add or strip headers, combine several back-end calls into one response.
  • Caching. Answer repeated requests without troubling the service.
  • Observability. One place for logs, metrics and traces of API traffic.
  • Developer experience. Documentation, API keys and usage plans for external users.

A concrete example is AWS's API Gateway, which throttles requests with the token bucket algorithm: a bucket refills at a steady rate (the allowed requests per second) and holds a maximum number of tokens (the burst), and each request takes a token. By default it limits an account to 10,000 requests per second per Region, with burst capacity from a bucket of up to 5,000 requests, and clients that exceed it get 429 Too Many Requests responses. You can set tighter limits per stage, per method or per client through usage plans tied to API keys. These are targets rather than guaranteed ceilings, according to the documentation.

A gateway for AI model traffic is a specialised version of the same idea, covered in our guide to the LLM gateway.

Two light panels: on the left a grey bucket with three circles above it, one orange circle falling in and an arrow leaving below, on the right a grey box with lines to three grey boxes, the lowest crossed out.
The gateway meters callers with a token bucket; the load balancer routes around a failed server.

API Gateway vs Load Balancer: Key Differences

The difference between API gateway and load balancer comes down to what each one understands:

QuestionLoad balancerAPI gateway
Does it care who is calling?Not normallyAlways
Does it enforce per-client limits?NoYes
Does it change requests?RarelyOften
Does it choose between different services?Between copies of one serviceBetween different services
Does it protect from overload?Spreads it outRejects or queues excess
What breaks if it fails?Traffic stops reaching the serversTraffic stops, and policy enforcement is lost
Natural ownerPlatform or infrastructure teamAPI or platform team

A load balancer treats every request as a unit of work to place somewhere. An API gateway treats each request as a call by a particular client to a particular operation, and applies policy. A layer 7 load balancer can look like a gateway because it can route by path and host and authenticate users, so the line blurs. A gateway, though, adds the API-specific parts: keys, plans, quotas, transformation and a developer portal.

Application Load Balancer vs API Gateway

Application load balancer vs API gateway is the comparison people search for most often, because the two overlap on path-based routing. The decision usually looks like this:

You needUse
Just spread HTTP traffic across identical servers, route by path or hostApplication load balancer
API keys, per-client quotas and usage plansAPI gateway
Request validation or transformation at the edgeAPI gateway
Lowest cost for very high request volumeLoad balancer (a gateway's per-request pricing adds up)
Non-HTTP traffic such as raw TCP or UDPNetwork (layer 4) load balancer
Serverless functions behind an HTTP API with built-in throttlingAPI gateway
Public API sold to third partiesAPI gateway

Cost is the other reason to be careful. The two are billed differently: load balancers are typically charged by hours and capacity used, while gateways often charge per request and for data transfer, so a gateway in front of a very high-volume internal service can cost far more than a load balancer doing the same routing. Check each provider's current pricing pages rather than relying on rules of thumb.

Which Comes First?

A common question is which comes first, the load balancer or the gateway. There's no single answer, but two patterns cover most systems:

Pattern 1: load balancer in front of the gateway. Clients reach a load balancer, which spreads traffic across several gateway instances (so the gateway isn't a single point of failure). Each gateway applies policy and forwards to services, often through another load balancer in front of each service's instances. This is common when you run your own gateway software.

Pattern 2: managed gateway at the edge. A cloud API gateway is itself a scaled, redundant service, so clients call it directly, and it calls load-balanced back ends. You don't put a load balancer in front of it.

In both patterns there are usually load balancers behind the gateway, because each back-end service has several instances. The rule of thumb: the gateway deals with callers, the load balancers deal with servers.

Worked Example: A Request Through a Shop's Stack

Take an online shop with an orders service and a catalogue service, each running on three instances, and a self-run gateway on three nodes. A request to GET /orders/42 travels like this:

StepComponentWhat happens
1Edge load balancerReceives the connection, terminates TLS, picks one of the three gateway nodes by health and load
2API gateway nodeChecks the API key, finds the customer's plan allows 100 requests per second, takes a token from their bucket
3API gateway nodeValidates the request, matches /orders/* to the orders service
4Internal load balancerChooses one of the three orders instances that is passing health checks
5Orders serviceReads the order and returns it
6API gateway nodeAdds headers, logs the call and returns the response

Now suppose one orders instance crashes. The internal load balancer's health check fails, it stops sending traffic there and customers notice nothing. Suppose instead a customer's script starts sending 500 requests per second: the load balancer would happily forward all of it, but the gateway's token bucket rejects the excess with 429 responses, protecting the orders service and every other customer. Each component fixed a problem the other couldn't.

A light panel with a grey square, a door-shaped box fanning three lines to three small boxes, the middle one orange, and below a light box with lines to three small grey boxes.
A request passes the gateway for policy, then a load balancer picks a healthy instance.

The vocabulary overlaps, so here is how the neighbours fit:

TermWhat it doesHow it relates
Reverse proxySits in front of servers and forwards client requestsGateways and load balancers are both specialised reverse proxies
CDNCaches content near usersSits in front of everything for static and cacheable content
WAFBlocks malicious requests by rulesOften attached to a load balancer or gateway
Service meshHandles service-to-service traffic inside a clusterControls east-west traffic; the gateway handles north-south
Ingress controllerRoutes external traffic into a Kubernetes clusterOften combines load balancing and gateway-like routing

North-south traffic (client to your system) is the gateway's world; east-west traffic (service to service) is the mesh's. Many tools, such as NGINX and Envoy, can play several of these roles, which is why the labels are fuzzy.

When Do You Need an API Gateway?

You likely don't need a gateway if you have one application on a few servers: a load balancer (or the web server itself) is enough. You likely do need one when:

  • You expose public or partner APIs and need keys, plans and quotas.
  • You run several back-end services and want one address and one place for authentication.
  • You need per-client throttling to protect shared services.
  • You want to version or retire APIs without changing clients.
  • You need consistent logging, metrics and policy across many teams.

A load balancer, by contrast, is needed as soon as you have more than one copy of a service or need to survive a server failure.

Common Mistakes

  • Treating them as alternatives. Most production systems use both, at different points.
  • Using a gateway to scale servers. A gateway applies policy; it doesn't replace load distribution and health checks for your instances.
  • Putting every service behind a gateway on the internal path too. Internal calls often need only a load balancer or mesh, and a gateway there adds latency and cost.
  • Making the gateway a single point of failure. Run several nodes or use a managed service.
  • Doing business logic in the gateway. It should enforce policy and route, not hold domain rules that belong in services.
  • Ignoring the cost model. Per-request pricing at high volume can be a surprise.
  • Skipping rate limits because "the load balancer will cope". A load balancer spreads load; it won't stop one client from consuming it.

FAQ

What is the difference between an API gateway and a load balancer?

A load balancer distributes traffic across identical servers for capacity and availability. An API gateway is the managed front door for APIs: it authenticates callers, enforces rate limits, transforms requests and routes to the right service.

Can a load balancer replace an API gateway?

Only for simple cases. A layer 7 load balancer can route by path and host and sometimes authenticate users, but it lacks API keys, per-client quotas, usage plans and request transformation. If you need those, you need a gateway.

Do I need both an API gateway and a load balancer?

Often yes. The gateway handles who is calling and which service to use, and load balancers spread each service's traffic across instances and remove failed ones. Small systems with one service may need only a load balancer.

Which comes first, the load balancer or the API gateway?

With a self-run gateway, a load balancer usually sits in front of several gateway nodes, and more load balancers sit behind the gateway. With a managed cloud gateway, clients call the gateway directly and it calls load-balanced back ends.

What is an API gateway used for?

An API gateway is used to give clients one entry point to many services, to check identity, to enforce rate limits and quotas, to validate and transform requests, to cache responses and to collect logs and metrics for API traffic.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog