AlgoViz

Hardware and software load balancers

easy 24 min

A hardware load balancer is an appliance you install, often with chips made for moving packets or encrypting.

Video lesson · Chapter 1 of 5

Trace one flow through the appliance

0:00 / 3:31

Built-in oven or camping stove: load balancers in 75 seconds

1:15Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

Every load balancer is a program running on some machine. With a hardware load balancer you buy the two together: an appliance from a vendor, with its own operating system, a support contract and often special chips.

With a software load balancer you bring the machine. NGINX, HAProxy, Envoy and Traefik run on a server, a virtual machine or a container. A cloud load balancer is a third choice: the provider runs it and you only configure it.

Why it exists

Moving packets and doing encryption is heavy, repeated work. Special chips can do a fixed kind of work very fast, so appliances were the normal answer for big sites for many years.

General processors, network cards and operating systems improved, and companies wanted to add capacity by starting another machine. Software balancers grew with that. Today the question is less "which is faster" and more "which fits how we operate".

A short history

  1. February 1996

    F5 is founded. Its BIG-IP line becomes one of the best-known families of load balancing appliances.

  2. November 2000

    The first lines of HAProxy are written, according to its change log.

  3. October 2004

    NGINX 0.1.0, the first public version, is released.

  4. March 2016

    Google publishes Maglev, a software network load balancer on ordinary Linux servers. The paper says it had served Google's traffic since 2008.

  5. May 2018

    Facebook releases Katran, which balances packets inside the Linux kernel with XDP and eBPF.

Words to know

Appliance
A machine sold for one job, with hardware and software from one vendor.
ADC
Application delivery controller: an appliance or product that balances, encrypts, caches and protects.
ASIC
A chip made for one task. Very fast, and cannot be changed later.
FPGA
A chip whose circuits can be configured after it is made.
CPS
Connections per second: how many new connections are opened each second.
Commodity server
An ordinary machine, not made for one product.
Active and standby
One works, the other waits to take over.
Sidecar
A small proxy that runs beside each service instance.

How it works

Step through the idea, or press Play.

Step 1 of 3

Measure the need. Connections, requests, bandwidth, TLS and delay

Understand it

Start here

The oven and the stove story

Imagine cooking for guests with a built-in oven or with camping stoves. The oven is strong and fixed to the wall. A stove is small, can stand anywhere, and you can bring another.

Cooking for a crowd
Built in and strong

Neither is simply better. It depends on the kitchen, the guests and who cooks.

Overview

Three forms of the same job

HardwareSoftwareCloud service
What you getAn applianceA programAn address and settings
Runs onVendor's machineYour server, VM or containerProvider's machines
ProcessingGeneral CPU, often with ASIC or FPGA helpGeneral CPU, network card and kernel featuresHidden from you
You look afterRack, power, firmware, contractMachines, updates, spare capacitySettings and limits
ExamplesF5, A10, NetScaler, Kemp appliancesNGINX, HAProxy, Envoy, TraefikLoad balancers of AWS, Azure, Google Cloud
The line is blurred: F5, A10 and Kemp also sell virtual or cloud editions of their products.

All forms can work at layer 4 and layer 7. The form tells you how it is delivered, not what it reads. Load balancing covers the rules that choose a server.

Hardware

Hardware load balancers

A pair of appliances

Users reach a data centre. Inside are two appliances, each its own machine: an active one and a standby one that receives its state. The active appliance sends traffic to two servers.
One is active. The standby copies its state and takes over the address if the first one fails.

What is in the box

  • Packet chips

    ASICs or FPGAs move known kinds of packets without the main processor.

  • Crypto processors

    Do part of the TLS work.

  • Network ports

    Many fast ports on one machine.

  • Spare parts

    Two power supplies, parts that can be changed while it runs.

Product families

ProductVendorWhat it is
BIG-IPF5Application delivery. Hardware with FPGA help, and virtual editions
NetScaler (earlier Citrix ADC)NetScalerApplication delivery controller
Thunder ADCA10 NetworksHardware, virtual, cloud, bare metal and container forms
LoadMasterProgress KempHardware, virtual and cloud load balancers
Memory, port speed and limits differ by model. Read the data sheet of the exact model and version.

Software

Software load balancers

Two balancers as pods

Users reach a Kubernetes cluster. A service address spreads connections over two load balancer pods, each its own box. Both pods send requests to two application pods.
The balancers are ordinary workloads. Add a pod to add capacity. Something must still give them one address.

Well-known programs

ProgramLayersKnown for
NGINX4 and 7Web server, reverse proxy and balancer
HAProxy4 and 7TCP and HTTP balancing
Envoy3, 4 and 7Edge and service proxy, often a sidecar in a service mesh
Traefik4 and 7Edge router that reads its routes from container platforms
Text
upstream shop {    least_conn;    server 10.0.0.1:8080 weight=2;    server 10.0.0.2:8080;}server {    listen 80;    location / {        proxy_pass http://shop;        proxy_http_version 1.1;        proxy_set_header Connection "";    }}

Because it is text, it can be reviewed, tested and stored in Git. Check a file with nginx -t, then nginx -s reload: new worker processes start with the new settings, and old ones finish the clients they have.

Speed

What does fast mean?

Four different speeds

MeasureQuestionMostly limited by
Connections per secondHow many new ones?TCP and TLS handshakes
Requests per secondHow many on open connections?Parsing and copying
BandwidthHow many bits?Network cards and memory
Open connectionsHow many at once?Memory
A product can be strong in one and weak in another. Always ask which was measured.

From new connections to open connections

L=λW20000 /s×5 s=100000L = \lambda W \qquad 20000\,/\text{s} \times 5\,\text{s} = 100000
Little's law: 20,000 new connections a second that each last 5 seconds means 100,000 open at once.

Old advice says hardware handles millions of connections a second and software only thousands. That is too simple. HAProxy's makers measured more than two million HTTP requests per second on one large Arm server in 2021, on open connections. Google's paper says one Maglev machine can fill a 10 gigabit link with small packets. Your number depends on TLS, message size and machine.

How much does the balancer's delay matter?

40.8−40.240.2≈1.5%\frac{40.8 - 40.2}{40.2} \approx 1.5\%
Assume the service takes 40 ms. A balancer that adds 0.8 ms instead of 0.2 ms changes the total by about 1.5 percent.

Growth

Scaling and spare capacity

Hardware grows

  • Change to a bigger model
  • Add a licence if the unit allows it
  • Buy another pair
  • Order early: delivery and rack space take time

Software grows

  • Start another instance
  • Use more cores
  • Scale up and down with traffic
  • Needs something to spread traffic over instances

How many software instances?

n=⌈30000080000×0.6⌉+1=7+1=8n = \left\lceil \frac{300000}{80000 \times 0.6} \right\rceil + 1 = 7 + 1 = 8
Assume a peak of 300,000 requests a second, 80,000 measured per instance, 60% planned use, and one spare.

Who balances the balancers?

DNS, a router that shares connections, or a floating address. See global and local load balancing.

Failure

When one fails

Standby takes over

With copied state, open connections may continue. Without it, clients reconnect.

Two boxes do not help if both think they are active. Use a second heartbeat path, and a rule that prevents a split brain. Test a failover on a normal day. Software can use the same pattern, or run many active copies and lose only a share.

Money

Cost over years

CostHardwareSoftwareCloud
StartHigh: usually two unitsLowNone
LicenceDevice, features, supportOften free, paid editions existUsage
PlaceRack, power, coolingServers or VMsIncluded
PeopleVendor skillsLinux and automation skillsCloud skills
GrowthIn stepsSmoothSmooth
EndReplace after support endsUpgradeProvider's schedule
Ask for a quote. Prices vary so much by model, licence and discount that a general range would mislead.

A break-even sum

1200003000=40 months\frac{120000}{3000} = 40\text{ months}
Invented figures to show the method: a pair costs 120,000 in all, and the alternative 3,000 a month in all. Add people and spare parts to both sides before you compare.

Operations

Changes and updates

TaskHardwareSoftware
Change a ruleVendor console, API or scriptText file or API, reviewed in Git
UpdateFirmware, standby firstRolling, a few instances at a time
ExtendVendor scripting and modulesModules, scripts, source code
SupportContract with the vendorCommunity, or a paid contract
Go backBoot the previous imageDeploy the previous version
Modern appliances have APIs too, so automation is a habit, not a property of one side.

Change a software balancer safely

  1. 1

    Generate

    Build the file from reviewed data, and refuse odd names or ports.

  2. 2

    Check

    Run the program's own syntax check.

  3. 3

    Try one

    Reload one instance and compare errors and delay.

  4. 4

    Continue

    Go on in steps. Keep the last good file ready.

Compare

Side by side

AspectHardwareSoftware
SpeedHigh and predictable for work its chips handleDepends on machine and setup. Can be very high
Added delayOften below a millisecondCan also be below a millisecond. More with TLS and rules
Start costHighLow
ScaleBigger unit or another pairMore instances
DeployRack in a data centreVM, container, cloud
UpdatesFirmwareRolling releases
FlexibilityWhat the vendor offersHigh
SupportOne vendor for allCommunity or contract
Often foundLarge own data centres, telecoms, banksWeb applications, microservices, clouds

Decide

Which one when

Hardware fits

  • Own data centre with steady, very high traffic
  • Measured need for special chips
  • A rule or contract asks for a certified appliance
  • One vendor to call, and budget for it
  • Staff already know the product

Software fits

  • Cloud or containers
  • Traffic that rises and falls
  • Cost at the start matters
  • Custom rules or scripts
  • Reviewed, automated changes
  • Many services that each need balancing

A short decision

A hybrid

The edge pair handles outside traffic. Software balancers route between services inside.

Summary

The whole topic in one minute.

Hardware comes as a finished appliance with support and special chips, and grows by buying a bigger or another unit. Software runs almost anywhere, is configured as text and grows by adding machines. Vendors sell both forms, and clouds offer a managed third.

Decide from measured needs: new connections, requests, bandwidth, encryption and the delay you can accept. Count the spare capacity, the people and the years. Test with your own traffic, and never believe a speed without knowing what was measured.

  • Hardware, software and cloud are ways to deliver the same job.
  • Ask which speed was measured, and with what traffic.
  • Hardware grows in large steps, software in small ones.
  • Every form needs a spare and a rehearsed failover.
  • Compare cost over years, with people included.

Sources