By Masoud Nikoofar | ictbank.ir
A load balancer sits in front of your servers and decides which one handles each request. That sounds like a single job, but “load balancer” is really a family of tools. They differ in the layer they work at, the way they are built, and the scope they cover. Picking the wrong one rarely breaks things on day one. It shows up later as a performance ceiling, a surprise bill, or an outage you could not route around.
This post walks through the main types and, more importantly, when each one fits. I group them by three questions: which layer does it work at, what form does it take, and how wide is its reach.
1. By layer: Layer 4 vs Layer 7
Layer 4 (L4): fast and simple
A Layer 4 load balancer works at the transport level. It sees IP addresses and ports (TCP or UDP) and makes its decision from that alone. It never reads the content of the request.
Strengths
- Very fast and lightweight, because it does little work per connection.
- Protocol-agnostic: it can balance databases, message brokers, mail servers, game traffic or anything else that runs over TCP/UDP.
- It can pass encrypted traffic straight through without holding your certificates.
Limits
- It cannot route by URL, header or cookie, because it does not understand them.
- It has limited visibility into what is actually happening inside the traffic.
Good fit: database traffic, non-HTTP protocols, and high-volume workloads where raw speed matters.
One practical note on databases: a load balancer does not make a single-primary database scale for writes. In practice, an L4 balancer is used to spread reads across replicas, or to always point clients at the current primary. For the second case the health check must understand database roles, not just whether the port is open. (That is a topic of its own, and it ties directly to a common health check mistake: checking only that a port is open.)
Layer 7 (L7): smart routing
A Layer 7 load balancer understands the application protocol, most often HTTP. It reads the request and can route based on what it finds: the hostname, the URL path, a header, or a cookie.
Strengths
- Content-based routing, for example sending
/apito one pool and/imagesto another. - TLS termination, so backends do not each have to handle encryption.
- Extras such as caching, compression, rate limiting, header rewriting and cookie-based session affinity.
Limits
- More CPU and memory per request, since it parses traffic instead of just forwarding it.
- Once it terminates TLS, it holds your certificates and sees plaintext, which has security and operational implications.
Good fit: websites, APIs and microservice architectures.
2. By form: hardware vs software
Hardware load balancers
These are dedicated appliances, built and tuned for high throughput and delivered with vendor support. F5 BIG-IP is a well-known example.
Strengths: high and predictable performance, mature feature sets, vendor support contracts.
Trade-offs: high purchase and maintenance cost, capacity that has to be planned in advance, and slower change cycles. Scaling usually means buying more hardware.
Good fit: large organizations with heavy, steady traffic and the budget and processes to match.
Software load balancers
These run on ordinary servers, virtual machines or containers. HAProxy, Nginx, Envoy and Traefik are common examples.
Strengths: flexible, inexpensive, easy to automate, and their configuration can live in version control like any other code.
Trade-offs: performance depends on the resources you give it and how well you tune it. You are also responsible for making the load balancer itself highly available, because a single instance is a single point of failure.
Good fit: most teams, and especially containerized and automated environments.
3. By reach: DNS-based and GSLB
The types above balance traffic between servers in one place. DNS-based load balancing, often called GSLB (Global Server Load Balancing), works one level higher. It answers DNS queries with different addresses depending on health, geography, latency or weights, which lets you spread traffic across multiple data centers or regions.
Strengths: multi-site distribution and a practical building block for disaster recovery.
Limits: DNS answers are cached. Because of TTLs, and because some resolvers hold on to records longer than they should, a switchover is never instant. It also balances at the level of clients and sites, not individual connections.
Good fit: multi-site deployments and disaster recovery.
How to choose
| If you need | Look at |
|---|---|
| High volume and non-HTTP traffic | L4 |
| Smart, content-aware routing | L7 |
| Flexibility and low cost | Software |
| Heavy, steady enterprise traffic with vendor support | Hardware |
| Multiple sites and disaster recovery | DNS / GSLB |
These are not mutually exclusive. Real systems often stack them: GSLB chooses the site, an L7 balancer routes by request, and an L4 balancer fronts the data tier. Each layer does the job it is best at.
Two things to remember
- A load balancer is only as good as its health checks. If it keeps sending traffic to a server that is up but unhealthy, balancing makes things worse, not better.
- The load balancer itself must not be a single point of failure. Whichever type you choose, plan for its high availability from the start.
Both are worth their own posts, and I will cover them next.
Which one do you use?
Are you running mostly HTTP traffic, or raw TCP such as databases? Tell me in the comments what your setup looks like, and I will be happy to discuss the trade-offs for your case.