# Layer 4 and layer 7 load balancing

> Choose between a balancer that forwards TCP connections quickly and one that reads each HTTP request so it can route by content.

A layer 4 balancer forwards connections without looking inside, and a layer 7 balancer reads the request and decides with what it finds.

## Use it when

- L7: you want to route by path, header, or kind of request, or retry a failed call on another server.
- L4: raw throughput and low latency matter more than routing, or the traffic is not HTTP.
- Either: a single balancer is the busiest node on the board.

## How it works

An L4 balancer works on IP addresses and ports. It picks a backend and passes the bytes along, so it does little work per request and handles very large volumes. An L7 balancer terminates the connection, parses HTTP, and can send `/api` to one pool and `/images` to another, add headers, and retry. Real examples are AWS's Network Load Balancer for L4 and its Application Load Balancer for L7.

Splitting pools by kind also isolates them: a flood of page views cannot starve the API servers.

## What it costs

L7 does more work per request, so it has a lower ceiling, costs more per request, and adds latency. L4 cannot see paths or retry a request, and it spreads load by connection, so one long-lived connection can pin a server.

## In Quorum

A [Load Balancer](https://wiki.playquorum.dev/components/lb.md) has a variant. L7 is the default, and L4 needs [L4 load balancing](https://wiki.playquorum.dev/research/l4-lb.md). L4 forwards every kind of request on every Link, so per-kind routing is gone. On an L7 balancer, each Link can carry only some kinds of request.





The glossary defines [load balancer](https://wiki.playquorum.dev/glossary/load-balancer.md). Pair this with [Load balancing algorithms](https://wiki.playquorum.dev/patterns/load-balancing-algorithms.md).

Source: https://wiki.playquorum.dev/patterns/layer-4-and-layer-7-load-balancing
