Load Balancing
Lesson 14Beginner1h 12mAssessment-backed

Load Balancing

Learn how load balancers distribute traffic, protect availability, perform health checks, and shape request routing.

What you will be able to do

Explain what a load balancer does in a scalable system.
Understand routing, health checks, TLS termination, and failover at a beginner level.
Compare L4 and L7 load balancing in practical terms.
Design around overloaded or unhealthy instances.
Map load balancing to AWS, GCP, Azure, Kubernetes, and ingress patterns.

A load balancer sits between clients and service instances. It spreads requests, removes unhealthy instances, and gives the system one stable entry point while the backend changes.

What Load Balancers Do

Load balancing is not only round-robin traffic distribution. Production load balancers route by protocol, path, host, health, region, weight, and sometimes user affinity.

Load balancer routing client traffic to healthy service instances
The load balancer keeps one entry point while routing only to healthy instances.
ResponsibilityWhy it matters
Traffic distributionPrevents one healthy instance from taking all traffic.
Health checksRemoves broken instances from rotation.
TLS terminationCentralizes HTTPS handling where appropriate.
RoutingSends /api, /static, or tenant traffic to correct targets.
FailoverKeeps service reachable when an instance or zone fails.
Connection handlingProtects services from connection spikes and slow clients.

L4 vs L7 Load Balancing

Layer 4 load balancing works at the TCP/UDP connection level. Layer 7 load balancing understands HTTP details such as host, path, headers, and sometimes cookies.

TypeSeesGood forExample
L4IP, port, TCP/UDPVery fast network-level routingDatabase proxy or TCP service.
L7HTTP path, host, headersAPI/web routing and policiesRoute /api to services and /assets to static backend.
Global load balancingRegion and edge healthMulti-region entry pointRoute users to nearest healthy region.

Scenario: Video Learning Platform

A learning platform serves course pages, API requests, image assets, video metadata, and assessment submissions. These flows should not all route the same way.

TrafficRouting choiceReason
Course pagesWeb frontend service/CDNRead-heavy, cacheable content.
Assessment submitAPI service with stricter timeoutsWrite path and scoring workflow.
Images/static assetsCDN/object storageAvoid hitting application servers.
Admin APIsSeparate route and auth policyHigher privilege and lower traffic.
Health checksDedicated lightweight endpointAvoid expensive checks that overload service.

Design principle

A load balancer can hide failed instances, but it cannot fix a bad health check, overloaded dependency, or stateful server that cannot receive any request.

Health Checks

Health checks decide whether an instance receives traffic. A poor health check can route users to broken servers or remove healthy servers during a temporary dependency issue.

Check typeWhat it meansRisk
LivenessIs the process running?Too shallow for dependency failures.
ReadinessCan this instance receive traffic?Should fail during startup or severe local issues.
Deep dependency checkCan key dependencies be reached?May eject all instances if shared dependency is down.
Synthetic transactionCan a real flow work?Useful but expensive and should not run too frequently.

Cloud Load Balancing

NeedAWSGCPAzure
HTTP/L7Application Load Balancer/API GatewayCloud Load Balancing/API GatewayApplication Gateway/API Management
TCP/L4Network Load BalancerNetwork Load BalancingAzure Load Balancer
Global edge routingCloudFront/Global Accelerator/Route 53Cloud Load Balancing/Cloud CDN/Cloud DNSAzure Front Door/Traffic Manager
Kubernetes ingressAWS Load Balancer ControllerGKE Ingress/GatewayApplication Gateway Ingress Controller
Service mesh routingApp Mesh/Istio on EKSAnthos Service Mesh/IstioOpen Service Mesh/Istio on AKS

Beginner Mistakes

  • Forgetting health checks when adding multiple instances.
  • Using a deep health check that removes every instance when a shared database has a temporary issue.
  • Keeping user session only in instance memory and then load balancing across instances.
  • Sending static assets through API servers instead of CDN/object storage.
  • Assuming load balancing solves database or external provider bottlenecks.

Guided Practice

Practice task

Design routing for a news website with web pages, login API, image assets, and admin routes. Choose which traffic should go through app servers and which should use CDN or separate policies.

Sample Answer

TrafficRouting
Public article pagesCDN plus frontend/app origin depending freshness.
Images and static assetsCDN backed by object storage.
Login APIL7 route to auth/API service with rate limiting.
Admin routesSeparate host/path with stricter auth and allowlist if needed.
Health checksReadiness endpoint that confirms app can accept traffic without expensive full dependency checks.

Before You Continue

  • You should know what load balancers do.
  • You should understand L4, L7, and global routing at a high level.
  • You should understand health check trade-offs.
  • You are ready to learn why stateless services make load balancing and scaling safer.