Load Balancer vs Rate Limiting: 5 Key Differences
There are two common ways to deal with excessive traffic on a website: load balancing and rate limiting…
An Application Load Balancer (ALB) distributes incoming requests across backend servers by inspecting the request itself, the HTTP host header, the URL path, cookies, methods. It works at Layer 7, which is what separates it from a Layer 4 load balancer that only sees addresses and ports.
That difference determines what you can do. A Layer 4 balancer forwards a TCP connection to a server. A Layer 7 balancer reads the request and can decide that /api/* goes to one pool and /images/* to another, from the same public address.
| Network LB (Layer 4) | Application LB (Layer 7) | |
|---|---|---|
| Decides on | IP address and port | Host, path, headers, cookies, method |
| Protocols | Any TCP or UDP | HTTP, HTTPS, gRPC, WebSocket |
| TLS termination | Optional, pass-through common | Usually terminates |
| Content-based routing | No | Yes |
| Latency | Lower | Slightly higher |
| Throughput | Very high | High |
| Preserves client IP | Natively | Via X-Forwarded-For |
| Health checks | TCP port open | HTTP status code on a real endpoint |
| Use for | Databases, game servers, non-HTTP protocols, extreme throughput | Web applications, APIs, microservices |
Choose Layer 4 when the protocol is not HTTP or when raw throughput and latency dominate. Choose Layer 7 for anything web-facing, the routing flexibility and meaningful health checks are worth the small latency cost.
X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Port.Step 2 has a consequence worth planning for: the backend sees the load balancer’s IP, not the client’s. Applications that log client addresses, rate limit, or apply geographic rules must be configured to trust X-Forwarded-For, and to trust it only from the load balancer, or clients can forge it.
This is the main reason to run an ALB:
| Condition | Example | Sends to |
|---|---|---|
| Host header | api.example.com | API servers |
| Path | /images/* | Static content servers |
| Path | /admin/* | Admin pool, with an IP restriction |
| HTTP method | POST | Write-capable instances |
| Header | User-Agent contains Mobile | Mobile-optimised backend |
| Query string | ?version=beta | Canary deployment |
| Source IP | Office range | Internal build |
Rules are evaluated in priority order and the first match wins, the same model as an ACL, and the same trap: a broad rule placed above a specific one makes the specific one unreachable.
| Algorithm | Behaviour | Good for |
|---|---|---|
| Round robin | Each backend in turn | Uniform backends and uniform requests |
| Least outstanding requests | Whichever has fewest in flight | Varied request cost, usually the better default |
| Weighted | Proportional to assigned weight | Mixed instance sizes, gradual rollouts |
| IP hash | Same client always to the same backend | Crude session affinity |
Round robin is the intuitive choice and often the wrong one. If some requests take 5 ms and others take 5 seconds, round robin will keep sending work to a backend already struggling. Least outstanding requests adapts automatically.
A health check that only confirms the port is open will keep routing traffic to a server whose database connection has failed. The endpoint should verify the things the application actually needs:
GET /health
{
"status": "ok",
"database": "ok",
"cache": "ok"
}| Setting | Typical | Consideration |
|---|---|---|
| Path | /health | Must not require authentication |
| Interval | 10–30 s | Shorter detects faster, adds load |
| Timeout | 5 s | Must be under the interval |
| Unhealthy threshold | 2–3 failures | 1 causes flapping on a transient blip |
| Healthy threshold | 2–5 successes | Prevents a recovering server being flooded immediately |
| Expected codes | 200 | Be strict, a 500 is not healthy |
Two failure modes to avoid. A health check that hits the database on every probe multiplies database load by the number of backends times the check frequency, cache the result for a few seconds. And a check that is too deep will mark every backend unhealthy when a shared dependency has a brief problem, taking the whole service down rather than degrading it.
Session affinity pins a client to one backend, usually with a cookie. It is sometimes necessary and is generally a symptom of an architectural problem:
The better answer is stateless backends with session data in a shared store, Redis, Memcached, or a database. Then any backend can serve any request, and scaling, deployment and failure all become simpler. Use sticky sessions when you cannot change the application, not as a design choice.
X-Forwarded-Proto instead of the connection scheme.X-Forwarded-For, and only from the load balancer’s addresses.An ALB works at Layer 7 and routes on HTTP content, host, path, headers. An NLB works at Layer 4 and forwards based on address and port only. Use an ALB for web applications, an NLB for non-HTTP protocols or extreme throughput.
An ALB normally does, which is what lets it read the request and route on it. You can re-encrypt to the backend if the traffic must stay encrypted internally.
Because the balancer opens its own connection to the backend. The original address is in the X-Forwarded-For header, which your application must be configured to read, and to trust only from the load balancer.
Only if the backends hold session state locally. Storing sessions in a shared cache removes the need and makes scaling and deployments much simpler.
Most often an idle timeout mismatch, the backend closes a connection the balancer still believes is open. Set the backend keep-alive longer than the balancer’s idle timeout.
At least two, in different availability zones or racks, so one failure does not take the service down. Beyond that, size for peak load with enough headroom that losing one instance does not overload the rest. See software load balancers for the wider comparison.
One response to “Application Load Balancer — How an ALB Works and When to Use One”
[…] 7 load balancers (Application Load Balancers) operate at the application layer, which is responsible for ensuring that data is delivered […]