Sub topic 8
Hardware, software and cloud load balancers
This chapter compares the three ways to run a load balancer: a dedicated hardware appliance, software on servers you manage, and a managed service from a cloud provider. It assumes you know the difference between Layer 4 and Layer 7 balancing, the common balancing algorithms, and how health checks work. You should also be comfortable reading a simple NGINX or HAProxy configuration. Earlier chapters covered what a load balancer does. This chapter covers what form it takes and how to choose.
One job, three packagings
All three kinds do the same work: accept client connections, pick a backend, forward traffic, and stop sending traffic to backends that fail. The differences are in who owns the machine, how capacity grows, how you configure it, and what it costs.
| Aspect | Hardware appliance | Software | Cloud managed service |
|---|---|---|---|
| Examples | F5 BIG-IP, NetScaler, A10 | NGINX, HAProxy, Envoy, Traefik, Linux IPVS | AWS ALB/NLB, Google Cloud Load Balancing, Azure Load Balancer and Application Gateway |
| Who runs the host | You, in your data center | You, on VMs, containers or bare metal | The provider |
| Scaling | Buy a bigger box or add a pair | Add instances, or tune the host | Automatic, within provider limits |
| Cost model | Large upfront cost plus support contract and licenses | Free or low license cost, plus the servers and your time | Pay per hour plus per unit of traffic |
| Configuration | Vendor GUI, CLI or API | Text files, config management, APIs | Console, CLI, infrastructure-as-code |
| Main risk | Capacity is fixed until you buy more | You carry the operational burden | Lock-in and limits you cannot change |
Hardware load balancers
A hardware load balancer is a vendor appliance. It is often called an application delivery controller (ADC) because it does more than balance: it also handles TLS, caching, compression, web application firewall rules and DNS-based traffic steering.
Hardware appliances became common because general-purpose servers in the early 2000s could not do TLS handshakes or forward packets at high rates. Vendors added custom chips (ASICs or FPGAs) and TLS acceleration cards. Packet forwarding and TLS handshakes ran in dedicated silicon, which gave predictable latency under load.
Strengths:
- High throughput on one box. A single appliance can handle tens or hundreds of gigabits per second of traffic.
- Predictable performance. Dedicated hardware paths do not compete with other processes for CPU.
- Rich feature sets and vendor support. Support contracts and certified features matter in regulated environments.
- Familiar to network teams. Many organizations already operate them.
Weaknesses:
- Capacity is bought in steps. You size for peak traffic years ahead, or you replace the box when you outgrow it.
- High cost. You pay for hardware, a support contract, and often feature licenses or throughput licenses.
- Slow change. Racking a pair of appliances takes weeks. Testing configuration changes requires a lab appliance or a virtual edition.
- Poor fit for dynamic backends. Pools of containers that appear and disappear every few minutes need API-driven updates. Vendors offer these, but the workflow is heavier than editing a text file.
Most vendors now also sell virtual editions that run as a VM. These keep the vendor's feature set and management model but give up the custom silicon, so performance depends on the host.
Software load balancers
A software load balancer is a program that runs on a general-purpose operating system. The most widely used are HAProxy, NGINX, Envoy and Traefik. Linux itself can balance at Layer 4 in the kernel through IPVS (also known as LVS), and Keepalived is often paired with it for failover.
Strengths:
- Low cost and fast iteration. Configuration is text. You can keep it in version control, review changes in a pull request, and roll back.
- Runs anywhere. The same configuration works on a laptop, in a container, in a data center or on a cloud VM.
- Horizontal scaling. When one instance is not enough, you add more and spread traffic across them with DNS, ECMP routing or a cloud network load balancer.
- Close to the application. In Kubernetes, ingress controllers and service meshes are software load balancers placed next to the workloads.
Weaknesses:
- You operate it. You patch it, monitor it, size it, and make it highly available. The earlier chapter on removing the single point of failure applies directly.
- Performance depends on the host. A well-tuned HAProxy on modern hardware handles very high connection rates. Reaching that point needs kernel tuning, such as file descriptor limits, connection tracking, and network interrupt settings.
- Packet rate limits at Layer 4. At extreme packet rates, a normal kernel network stack becomes the bottleneck. Large operators use kernel-bypass or eBPF-based balancers for that case, for example Katran or Cilium.
Here is a minimal software setup in HAProxy. It balances HTTP across two backends with active health checks:
defaults
mode http
timeout connect 5s
timeout client 30s
timeout server 30s
frontend web
bind *:80
default_backend app
backend app
balance leastconn
option httpchk GET /healthz
http-check expect status 200
server app1 10.0.0.11:8080 check
server app2 10.0.0.12:8080 checkEverything about this load balancer is in the file above and the machine it runs on. That is the main appeal of software: you can see and control all of it.
Cloud load balancers
A cloud load balancer is a managed service. You describe a listener, a set of targets and health check settings. The provider runs the data plane on its own fleet, replaces failed nodes, and scales capacity without you managing instances.
Providers usually offer several products, split along the Layer 4 and Layer 7 line:
| Provider | Layer 7 (HTTP) | Layer 4 (TCP/UDP) | Other |
|---|---|---|---|
| AWS | Application Load Balancer (ALB) | Network Load Balancer (NLB) | Gateway Load Balancer, for inserting firewall and inspection appliances |
| Google Cloud | Application Load Balancers | Network Load Balancers | Global and regional variants of each |
| Azure | Application Gateway | Azure Load Balancer | Front Door for global HTTP routing |
The Layer 7 products understand HTTP. They route by host name and path, terminate TLS, integrate with certificate managers, and often connect to web application firewalls. The Layer 4 products handle TCP, UDP and TLS passthrough at very high rates with low latency, and often provide static IP addresses.
Here is an AWS CLI sketch that creates an internet-facing network load balancer and a target group. Replace the subnet and VPC IDs with your own:
aws elbv2 create-load-balancer \
--name demo-nlb \
--type network \
--scheme internet-facing \
--subnets subnet-0aaa1111 subnet-0bbb2222
aws elbv2 create-target-group \
--name demo-targets \
--protocol TCP \
--port 8080 \
--vpc-id vpc-0ccc3333 \
--target-type instanceYou would then register targets with register-targets and create a listener with create-listener. In practice most teams express this in Terraform or CloudFormation instead of typing commands.
Strengths:
- No capacity planning for the balancer itself. The service scales with traffic.
- Built-in redundancy. The provider runs nodes in multiple availability zones. You do not build the failover pair.
- Tight integration. Targets can be autoscaling groups, containers or serverless functions. Certificates, logging and access control come from the same platform.
- Pay as you go. Cost tracks usage, which suits variable or small workloads.
Weaknesses:
- Limits you cannot change. Examples are idle timeouts, maximum header sizes, the algorithms offered, and per-account quotas. An ALB's default idle timeout is 60 seconds, so a long-running request that stays silent longer than that is closed unless you raise the setting or send keepalive data.
- Changing IP addresses. Layer 7 balancers are usually reached by a DNS name that resolves to several addresses that change over time. Never hard-code or cache those IPs. If a partner needs a fixed IP to allow-list, use a Layer 4 balancer with static or elastic addresses.
- Cross-zone behavior. Some services spread traffic evenly across zones by default, and others do not. Cross-zone traffic may also cost money. Check the defaults for your provider.
- Client address handling. A Layer 7 cloud balancer opens its own connection to your backend, so the backend sees the balancer's address. The client address arrives in the
X-Forwarded-Forheader. Layer 4 balancers may preserve it or use the PROXY protocol, depending on configuration. - Lock-in. Rules, annotations and health check semantics differ between providers. Moving clouds means rewriting this layer.
Hybrid designs
Real systems often combine kinds. Common patterns:
- Cloud edge, software inside. A cloud Layer 4 balancer gives a stable address and spreads load across a fleet of HAProxy or Envoy instances. Those instances apply the complex Layer 7 routing rules you want to control.
- Cloud load balancer in front of Kubernetes. A managed balancer sends traffic to ingress controller pods, which route by host and path to services.
- Hardware plus cloud. An organization with a data center keeps its appliances for existing applications and uses cloud balancers for new workloads. A DNS-based global layer sends users to either.
Keeping a single configuration format for most of the fleet reduces mistakes. Mixed designs make sense only when each tier has a clear job.
Choosing among them
Work through these questions in order:
- Where do the backends run? In a public cloud, the managed service is the default. In your own data center, choose between appliances and software.
- What traffic do you carry? Plain HTTP routing fits any kind. Extreme packet rates, non-HTTP protocols, or requirements for static IPs point to a Layer 4 balancer.
- How fast does traffic change? Spiky or unpredictable load favors managed services or software fleets that can scale out.
- Who will operate it? A small team often benefits from a managed service. A team with strong network skills may prefer to control HAProxy or Envoy directly.
- What are your constraints? Compliance rules, vendor contracts, existing skills and budget structure (capital cost versus monthly operating cost) can override technical preferences.
- How hard is it to leave? Keep configuration in code, and prefer standard behaviors such as health check paths and forwarded headers, so you can change tiers later.
Common mistakes
- Treating the cloud balancer as a black box. When a request fails with a 502 or 504 status code, the cause can be a backend timeout, a closed idle connection or a failed health check. Turn on access logs from the start.
- Running one software instance. A single HAProxy server is a new single point of failure. Use at least two, with failover.
- Ignoring licensing. Hardware and virtual appliances may limit throughput or features by license. Check what happens when traffic exceeds the licensed level.
- Sizing for average load. Size for peak plus the loss of one node or zone, because that is when capacity matters most.
Exercise
A team runs a payment API in a public cloud. A partner bank requires a fixed set of IP addresses to allow-list, and the API must also route requests by URL path to different services. Which cloud load balancer design satisfies both needs, and why?
Show answer
Put a Layer 4 network load balancer with static (elastic) IP addresses in front, and forward its traffic to a fleet of Layer 7 balancers or proxies such as HAProxy, NGINX or Envoy that route by path. A Layer 7 managed balancer such as an ALB is reached through changing DNS-resolved addresses, so it cannot give the bank a fixed allow-list. The Layer 4 balancer provides the stable addresses, and the Layer 7 tier provides path-based routing. A Layer 7 managed balancer placed behind the Layer 4 balancer is also acceptable if the provider supports that target type.
Exercise
Name two reasons a team might choose software load balancers over a hardware appliance, and one risk they take on by doing so.
Show answer
Reasons: configuration is text that can be version-controlled and changed quickly, and capacity grows by adding instances on commodity hardware or VMs instead of buying a bigger box. Costs are also usually lower. Risk: the team must operate, patch, monitor and make the balancer tier highly available itself, and must tune the host to reach high connection or packet rates.