Engineering · 5 min read
Load Balancer: One Entrance, Many Backends by Rule
A load balancer is the single entrance to the origin. Longest prefix match versus priority order, and why a cache can hide inside the load balancer itself.
A load balancer is the single entrance to the origin. It reads the host, path, and headers, then picks a backend.
I used to think the origin was “one server.” Later I learned the origin is often a load balancer with several kinds of backends behind it.
- HTTP load balancer (layer 7): it understands URLs and headers, so it can route by path. A layer 4 load balancer sees only IP and port.
- A backend can be storage or a group of programs. Every cloud platform has both kinds of backend, but the names differ.
Two Ways to Match
- The
locationprefix in nginx is the first kind. When a rule must read a header, you can usually use only the second kind, and then order matters. - Our platform allows only one way to match in one set. One of our rules reads a header, so all rules must be ordered. If the order is wrong, some paths cannot reach the right backend (How the Load Balancer Picks a Backend).
The Cache May Live Inside the Load Balancer
- Some platforms make the cache a switch on each backend of the load balancer. Each backend has its own cache rules.
- Then, under the same load balancer, some backends have a cache and some do not. The rules also differ (A Bypass Header Works Only Where a Rule Reads It).
A load balancer does more than route. It can also be another cache layer that you did not notice.
Sources: nginx: location
Related: The Path of One Request, How the Load Balancer Picks a Backend, A Bypass Header Works Only Where a Rule Reads It. Or go back to the series overview.