AlgoViz

Layer 4 and layer 7 load balancers

medium 26 min

A layer 4 load balancer chooses a server from addresses and ports and keeps a whole connection on it.

Where it shows up

The same pattern appears across everyday software.

  • AWS Network Load Balancer

    Its documentation says it works at the fourth layer, and that for TCP it picks a target with a hash of the protocol, addresses, ports and TCP sequence number.

  • AWS Application Load Balancer

    Works at the seventh layer. Its rules can match host, path, method, source address, headers and query string. It can also be a target of a Network Load Balancer.

  • NGINX

    The http module proxies requests. The stream module proxies TCP and UDP, and its ssl_preread module reads the requested server name without ending TLS.

  • Cloudflare Unimog

    Cloudflare described a layer 4 balancer of its own in 2020, used to spread load between servers inside its data centres.

  • Envoy

    Its documentation describes a layer 3 and 4 network proxy at its core, with an HTTP layer built on top as filters.

  • Traefik

    Has separate routers for HTTP, TCP and UDP, so one product can work at both layers.