← Lessons

quiz vs the machine

Platinum1760

Networking

The TCP versus HTTP Load Balancer

How balancing at layer four differs from balancing at layer seven.

5 min read · advanced · beat Platinum to climb

Two layers, two views

A load balancer can operate at different layers of the stack, and the choice changes what it can see and do.

A TCP load balancer works at layer four. It forwards connections based on IP addresses and ports without parsing the bytes inside. It is fast and protocol agnostic, balancing anything that runs over TCP, but it cannot read paths, headers, or hostnames.

An HTTP load balancer works at layer seven. It terminates the connection, parses the request, and can route by URL path, host header, cookies, or method. This enables path based routing, header rewriting, and per request retries, at the cost of more work per request.

What each enables

  • Layer four: raw throughput, low latency, any TCP protocol, no content awareness.
  • Layer seven: smart routing, content based decisions, TLS termination, richer observability.

Combining them

Large systems often stack both: a layer four balancer spreads connections across a fleet of layer seven proxies, which then make content aware routing decisions. This gets the throughput of layer four and the intelligence of layer seven.

Key idea

A TCP balancer forwards connections fast without seeing content, while an HTTP balancer parses requests to route by path, host, and headers.

Check yourself

Answer to earn rating on the learn ladder.

1. What can an HTTP load balancer do that a TCP load balancer cannot?

2. Why do large systems often stack layer four and layer seven balancers?