AlgoViz

Cloud load balancing

medium 25 min

A cloud load balancer is a load balancer you rent.

Video lesson · Chapter 1 of 5

Find the global door and the regional worker

0:00 / 4:03

Theory

Read or listen first. About 2 min.

What it is

A cloud load balancer is a load balancer offered as a service. You do not buy a box or install a program. You describe what you want: which port to listen on, which certificate to use, which servers may receive work. The provider creates it and keeps it running.

Behind the one name you get there are many machines, in several separate buildings called zones. When traffic grows, the provider adds more of them. When one breaks, the provider replaces it. This is what managed means.

Each large cloud offers a small family of balancers: one that reads web requests (layer 7), one that only forwards connections (layer 4), and one that spreads users over regions. Learning the family is learning the topic.

Why it exists

Running your own balancers means at least two of them, a way to move an address from one to the other, operating system updates, certificates, capacity planning and somebody awake at night. A small team would rather build its product.

A rented balancer also knows about the other things you rent. A new virtual machine or container can join its target group by itself, a certificate can renew by itself, and its logs go to the same place as the rest.

The price is less control. You accept the limits of the service, its way of counting money, and the work of moving if you change provider.

A short history

  1. Spring 2009

    Amazon launches Elastic Load Balancing, together with Auto Scaling and CloudWatch.

  2. August 2016

    The AWS Application Load Balancer: routing by the content of the request, with target groups.

  3. September 2017

    The AWS Network Load Balancer: layer 4, one fixed address per zone, millions of requests per second.

  4. November 2020

    The AWS Gateway Load Balancer, for fleets of firewalls and similar appliances.

  5. September 2025

    Microsoft retires the Basic tier of Azure Load Balancer in favour of the Standard tier.

  6. April 2026

    Microsoft retires version 1 of Application Gateway. Version 2 scales by itself and can span zones.

Words to know

Managed
The provider handles scaling, patching and availability. You handle the settings.
Region and zone
A region is a place. A zone is a separate part of it that should not fail together with the others.
Listener
The port and protocol where the balancer accepts traffic.
Rule
If the host or path looks like this, send the request there.
Target group
The machines, containers or functions that may receive the traffic, with one health check. Google calls it a backend service, Azure a backend pool.
Cross-zone balancing
A balancer node may send work to targets in other zones as well as its own.
Anycast
One address announced from many places. The network takes each user to a near one.
Capacity unit
The measure the provider bills by, such as the LCU on AWS.

Understand it

Start here

A marquee that grows with the party

Hire the marquee and its staff

Noor still chose the garden, the number of chairs and the menu. A managed service does not decide those.

At the partyIn the cloud
Hire companyCloud provider
Marquee with staffManaged load balancer
Tents in two corners of the gardenNodes in two zones
Chairs and foodYour servers, which you must still size
BillHourly price plus usage

The idea

What managed means, and what it does not

Four benefits

  • Managed service

    No hardware to buy, rack, patch or replace.

  • Automatic scaling

    The balancer itself grows and shrinks with traffic.

  • Distribution

    Over zones always, over regions with the global kinds.

  • Pay per use

    A price per hour and a price for usage.

Who does what

TaskProviderYou
Balancer machines, patchesYesNo
Size of the balancerYesChoose the kind, know its quotas
Zones to useOffers themChoose at least two
Health check path and limitsRuns itDesign it
Enough healthy serversNoYes, or an auto scaler you set up
CertificatesCan renew its ownAsk for them, prove the domain is yours
Rules, firewall, loggingOffers themSwitch them on

How a balancer picks a server belongs to load balancing. Layers are explained in layer 4 and layer 7. This page is about renting one.

Parts

The same five parts in every cloud

  1. 1

    Front end

    The name or address that clients use.

  2. 2

    Listener

    A port and protocol, with a certificate if it ends TLS.

  3. 3

    Rules

    Host and path decide which group gets the request. Layer 4 balancers have only the port.

  4. 4

    Target group

    The servers, containers, addresses or functions. On AWS an application balancer can also target a Lambda function.

  5. 5

    Health check

    How the balancer learns which targets may receive traffic.

One managed balancer over two zones

DNS gives users the addresses. They send HTTPS to a managed application load balancer with a node in zone A and a node in zone B. Each node sends HTTP to servers in both zones.
The balancer is one resource to you. Behind its name are nodes in every zone you enabled.

From a name to a server

The provider changes the addresses when the balancer grows. Always use the DNS name, never a copied address.
Python
lb = aws.lb.LoadBalancer("app-lb",    load_balancer_type="application",    security_groups=[security_group.id],    subnets=[s.id for s in subnets],          # one per zone    enable_deletion_protection=True,    access_logs={"bucket": logs.bucket, "prefix": "alb-logs", "enabled": True})group = aws.lb.TargetGroup("app-tg",    port=80, protocol="HTTP", target_type="ip", vpc_id=vpc.id,    health_check={"path": "/health", "healthy_threshold": 2,                  "unhealthy_threshold": 3, "interval": 30, "timeout": 5})aws.lb.Listener("https",    load_balancer_arn=lb.arn, port=443, protocol="HTTPS",    certificate_arn=certificate.arn,    default_actions=[{"type": "forward", "target_group_arn": group.arn}])
The same thing as code, with Pulumi in Python (it needs an AWS account, so it does not run here). Names such as subnets are defined elsewhere.

AWS

Elastic Load Balancing

KindLayerUse it forRemember
Application (ALB)7HTTP, HTTPS, gRPC; rules by host and pathTargets can be instances, IP addresses or Lambda
Network (NLB)4TCP, UDP, TLS; very low latency, sudden trafficOne static address per zone
Gateway (GWLB)3Fleets of firewalls and other virtual appliancesSends packets on with GENEVE, port 6081
Classic (CLB)4 and 7Nothing newAWS calls it the previous generation

Four features that interviews ask about:

  • Cross-zone balancing: always on at the balancer level for ALB (a target group can switch it off), off by default for NLB and GWLB.
  • Target groups: EC2 instances, containers (by IP address), Lambda functions.
  • Sticky sessions: with a cookie on ALB. See sticky sessions for what they cost you.
  • Health checks: HTTP or HTTPS, also in gRPC form on ALB, and plain TCP on NLB. ALB defaults for instances: every 30 seconds, 2 failures to remove, 5 successes to return.

Google Cloud

Cloud Load Balancing

KindLayerUse it for
Global external Application7Web traffic for the world on one anycast address
Regional external Application7Web traffic that must stay in one region
Proxy Network4TCP that the balancer ends and opens again
Passthrough Network4TCP, UDP and others, client address preserved
Internal (Application or Network)7 or 4Traffic inside your private network

What stands out:

  • Global anycast: a single address in front of backends in many regions. Users reach a nearby Google location first.
  • HTTP/2 and gRPC to clients and to backends.
  • Cloud Armor: filtering and protection against floods, attached to the external application balancer.
  • Cloud CDN: caching switched on at the balancer. Google also says its balancers need no warming before a peak.

Azure

Four services with four jobs

ServiceLayerScopeUse it for
Application Gateway7RegionalWeb traffic, TLS, path rules, web firewall
Azure Load Balancer4Regional or cross-regionTCP and UDP, zone-redundant front end
Front Door7GlobalContent delivery and global balancing together
Traffic ManagerDNSGlobalChoosing a region by DNS, any protocol

Version 2 of Application Gateway scales by itself and can be zone redundant. Private Link gives private connections to services. Traffic Manager only answers DNS questions, so Microsoft warns that it cannot fail over as fast as Front Door: some resolvers keep old answers.

Side by side

Translate between the three clouds

NeedAWSGoogle CloudAzure
Layer 7, one regionALBRegional Application LBApplication Gateway
Layer 4, one regionNLBNetwork LBLoad Balancer
One entry for the worldGlobal Accelerator (layer 4) or CloudFrontGlobal Application LBFront Door
DNS-basedRoute 53Cloud DNS policiesTraffic Manager
Web firewallAWS WAFCloud ArmorWAF on App Gateway or Front Door
Servers behind itTarget groupBackend serviceBackend pool
Close relatives, not twins. Read the limits of the one you use.

Choose by three questions

A global entry over regional balancers

Users everywhere connect to one global entry on an anycast address. It sends traffic to a regional balancer in region Europe and a regional balancer in region Asia, each in front of its own servers.
The global entry ends connections near the user and picks a region. See global and local load balancing for how it chooses.

Choosing a region is the subject of global and local load balancing.

Zones

Cross-zone balancing and unequal zones

DNS spreads clients evenly over the zones. Suppose zone A has 1 target and zone B has 3. With cross-zone balancing off, each zone keeps its own half of the traffic.

Share per target, cross-zone off and on

off: A=50%1=50%,B=50%3≈16.7%on: 100%4=25% each\text{off: } A = \frac{50\%}{1} = 50\%,\quad B = \frac{50\%}{3} \approx 16.7\% \qquad \text{on: } \frac{100\%}{4} = 25\% \text{ each}
The lonely target in zone A gets three times the load of the others. Switch it on or keep the zones equal.

Cross-zone traffic can cost money per gigabyte on some balancers and adds a little delay. That is the reason to switch it off on purpose, with equal zones.

A zone fails

When zone A goes, its address leaves DNS and its servers leave the group. The rest must be able to carry the peak.

Servers to buy so that a zone may fail

nper zone=⌈peak loadper server×(z−1)⌉n_{\text{per zone}} = \left\lceil \frac{\text{peak load}}{\text{per server} \times (z - 1)} \right\rceil
Peak 9,000 requests a second, 500 per server, 3 zones: 9,000 / (500 x 2) = 9 per zone, 27 in total. Without the spare you would need 18.

Health

How long a dead server still gets traffic

Detection time

t≈interval×failures needed+timeoutt \approx \text{interval} \times \text{failures needed} + \text{timeout}
AWS defaults for ALB with instances: 30 x 2 + 5 = about 65 seconds at worst. Interval 10, 2 failures, timeout 2: about 22 seconds.

Three settings go together with the check:

  • Deregistration delay: before a target leaves, the balancer stops new requests and waits for running ones. The AWS default is 300 seconds. Match it to your longest normal request.
  • Slow start: a new target receives a growing share instead of a full share at once, useful when caches are cold.
  • All targets unhealthy: application balancers on AWS then fail open and use them all. Do not build alarms that assume traffic stops.

Life of a target

Money

You pay for the largest measure

Providers charge a price per hour plus capacity units. On AWS one unit of an application balancer (LCU) covers, each measured per hour or second, the amounts below. You pay for the dimension you use most, not for the sum.

DimensionOne LCU coversExample loadLCUs
New connections25 a second232 a second9.3
Active connections3,000 a minute30,00010
Bytes processed1 GB an hour83 GB an hour83
Rule evaluations1,000 a second0 above the free 10 rules0
Example load: 100 million requests a day, 20 KB each, one new connection per five requests. Billed: 83 LCUs on average.

The arithmetic: 100,000,000 / 86,400 = 1,157 requests a second on average. Times 20 KB is 23 MB a second, or 83 GB an hour. At a peak of 3 times the average it is 250 LCUs for those hours. Bytes decide here, so compressing responses or serving pictures from a CDN saves more than anything done to connections.

Own or rent

When renting is wrong

Rent it

  • A small team, or traffic that jumps.
  • Servers already in that cloud.
  • Normal web rules, certificates and logs.
  • Several zones without effort.

Run your own

  • You need a rule or protocol the service lacks.
  • Very high steady traffic where the bill beats a team.
  • The same setup must run in several clouds or on your own site.
  • Addresses or hardware that must be yours.

Between the two there is a common mix: a rented layer 4 balancer in front, your own proxies behind it for the rules.

Summary

The whole topic in one minute.

A managed balancer takes the machines, the patching and the growth off your hands. It does not take the design off your hands: you still choose the kind, the zones, the health check and the spare capacity.

Choose by three questions. Web requests or plain connections? One region or many? Must the address stay fixed? Then read how it is billed, because you pay for the largest of several measures.

  • Managed means the provider scales, patches and replaces the balancer. Servers, checks and settings stay yours.
  • AWS: ALB for layer 7, NLB for layer 4, GWLB for appliances. Google: global anycast. Azure: Application Gateway, Load Balancer, Front Door, Traffic Manager.
  • Use the DNS name. The addresses behind it change.
  • Know whether cross-zone balancing is on, and keep one zone of spare capacity.
  • Detection takes interval times failures. Tune it.
  • You pay for the largest measure. Often that is bytes.

Sources