Send all your traffic to one machine and it buckles. Load balancing is the layer that fans
requests across many servers โ and it starts, surprisingly, at the level of the domain name you type in.
๐งญ
How to read this
The chapter follows the path a request actually takes: it starts as a domain name, gets resolved to an IP
through DNS, and lands on a balancer that picks a server. So we cover the problem first, then DNS (the
machinery you must understand before load balancing makes sense), then the balancing methods and algorithms
themselves. Anything marked [+] is context I added; everything else is rewritten
from the five teaching lessons.
01
One server can't hold the whole crowd
A load balancer distributes incoming traffic across the servers in a cluster so no single machine gets
overwhelmed. It's a key component of web architecture, and it exists to prevent a specific failure:
if all traffic converges on one or a few machines, those machines overload โ latency spikes, performance drops,
and the nodes can go offline entirely. Spreading the requests avoids that mess.
The balancer also props up availability. If a server dies mid-request, the balancer simply routes future
requests to the machines still running, so the service as a whole stays up. It acts as the single point
of contact for every client request โ clients talk to the balancer, and the balancer decides which
server actually answers.
๐ค
One vocabulary note from the course
Node, server, server node, instance, and machine all mean the same thing
here and are used interchangeably.
Balancers aren't only for the front door. They can sit in front of any application component โ
backend app servers, the database, a message queue โ to spread request load evenly across the machines powering
that specific component.
Figure 1 โ The balancer is the single point of contact: clients hit it, and it distributes
each request across the healthy servers.
02
The balancer only trusts servers it can hear
To route intelligently, a balancer must know which servers are actually alive โ so it runs regular
health checks. It keeps a real-time list of the machines that are up, and forwards requests only to
those. A machine that's up is in-service; a machine that's down is
out-of-service. When a server fails a health check, it's dropped from the list. When it
recovers and passes again, the balancer adds it back and resumes routing to it.
๐ฉบ
Why this matters for the DNS method later
Hold onto this idea. The health-check list is exactly what DNS-level load balancing lacks โ and
that gap is the main reason DNS balancing is the crudest of the methods you'll meet in Section 05.
03
DNS turns names into numbers
Every machine on the web has a unique IP address, and DNS is the system that lets you reach one without
memorizing it. IP (Internet Protocol) delivers data packets between machines using those addresses โ
something like 2001:db8:0:1234:0:567:8:1. Nobody can hold addresses like that in their head, so the
Domain Name System (DNS) maps a memorable domain name such as amazon.com to its IP address for you.
When you type a URL and hit enter, that event is called DNS querying. Resolving the name
involves four kinds of servers working in a chain:
DNS component
Its job
DNS Recursive nameserver (aka DNS Resolver)
Receives your browser's request and does the legwork of walking the chain. Usually run by your ISP.
Root nameserver
Points the Resolver to the right top-level domain nameserver.
Top-Level Domain (TLD) nameserver
Holds data for a whole extension โ the .com TLD server knows about all .com
domains, .edu for .edu, and so on.
Authoritative nameserver
The final server in the chain; owned by the domain's owner. Returns the domain's actual IP address.
04
Following a query through all four servers
Here's the full lookup for amazon.com, step by step.
Browser โ Resolver. You hit enter; the browser sends the request to the DNS Resolver (recursive
nameserver), typically managed by your ISP.
Resolver โ Root. The Resolver asks the Root nameserver where to find the right TLD server. The
Root returns the address of the .com TLD nameserver.
Resolver โ TLD. The Resolver queries the .com TLD server, which returns the
address of the amazon.com authoritative nameserver.
Resolver โ Authoritative. The Resolver queries the authoritative nameserver, which returns the
actual IP address of amazon.com.
Resolver caches โ Browser. The Resolver caches the result and hands the IP to your browser,
which then requests the site directly from that IP.
Caching keeps this fast. The whole DNS infrastructure is a distributed system living in large
ISP data centers, with server clusters tuned to answer queries in milliseconds. Results are cached along the way
โ and your own device caches DNS records too, with a TTL (Time To Live). Modern browsers do this
automatically to skip the lookup on repeat visits.
Figure 2 โ The DNS query lookup chain. The Resolver walks Root โ TLD โ Authoritative, caches
the IP, and returns it so the browser can hit the site directly.
05
The first place to balance: the authoritative server
A service the size of amazon.com runs across many data centers worldwide, and DNS load
balancing spreads traffic across them right at the authoritative nameserver. Instead of returning a
single IP, the authoritative server returns a list of IPs for the domain โ and with each query it
rotates the order of that list in round-robin fashion.
The client tries the first IP on the list; the reason it gets a whole list is so it can fall back to the next
IP if the first doesn't respond in time. The next client's query gets the list re-ordered with a different IP on
top, and so on. Note that the IP a client hits may not be an application server directly โ it's often
another load balancer at the data-center level that manages that site's server clusters.
Figure 3 โ Round-robin DNS: each client receives the same IPs in a rotated order,
distributing which server they try first.
โ ๏ธ
Why DNS balancing is the blunt instrument
It ignores everything the balancer in Section 02 tracks: current server load, the content a server holds,
request-processing time, and in-service status. Worse, because clients and Resolvers cache those
IPs, a request can still be routed to a machine that's already out of service. Companies use it anyway โ
across multiple data centers โ because it's cheap and easy to set up.
06
Hardware or software โ pick your balancer
There are three modes of load balancing overall: DNS (covered above),
hardware-based, and software-based. The latter two are the common ways to
balance traffic on large-scale services.
Hardware load balancers
Software load balancers
What they are
Dedicated high-performance physical appliances that sit in front of the app servers.
Software installable on commodity hardware and VMs; also available as LBaaS (Load Balancer as a
Service) with no setup.
Routing inputs
Open connection count, compute utilization, and other parameters.
Far more advanced โ data hosted by servers, cookies, HTTP headers, CPU/memory use, network load, plus
continual health checks.
Cost & ops
Expensive; need maintenance, updates, and a specialist skill set. Must be over-provisioned upfront for
peak traffic.
Cost-effective, flexible, easy to upgrade and provision on demand.
Verdict
Best raw performance โ if you have a network/IT team to run them.
Preferred by dev teams because they don't need specialists to manage. e.g. HAProxy,
used by GitHub, Reddit, Instagram, AWS, Tumblr, and StackOverflow.
The trade-off in one line: hardware wins on peak performance, software wins on cost, flexibility, and how much
smarter its routing decisions can be โ which brings us to the algorithms.
07
How a balancer actually picks a server
DNS balancers only know round robin. Software balancers add several smarter algorithms.
Round robin & weighted round robin
Round robin hands out server IPs sequentially, ignoring load, CPU, or anything else.
Weighted round robin fixes the blind spot: each server gets a weight based on its compute and
traffic-handling capacity, and traffic is distributed in proportion to those weights. More traffic flows to the
beefier machines โ useful when a service spans multiple data centers of different sizes, so the larger ones
absorb more.
Least connections
Routes the next request to the machine with the fewest open connections. Two flavors:
Naive: assumes every request costs the same resources โ but the machine with the fewest
connections might already be pinned at high CPU, so sending more there is a bad bet.
Resource-aware: also weighs CPU utilization and request-processing time. The ideal target
has the shortest processing time, lowest CPU use, and fewest open connections.
Least connections shines when connections stay open a long time โ like persistent connections in a gaming
application. [+]
Random
Routes traffic to servers at random. The balancer may also group servers that look similar (by existing load,
processing time, etc.) and then randomly pick among that similar set.
Hash
Hashes the source IP and/or the request URL to decide the target โ and the
payoff is stickiness:
Figure 4 โ Hashing for stickiness. Hashing the client IP pins a user to one server (session
stays warm); hashing the URL pins a resource to one cache (avoids misses and duplication).
Hashing the source IP guarantees a given client always lands on the same server. That server
already holds the client's data in local memory, so it skips fetching session data from the cluster's shared
session store โ lower latency โ and lets the client re-establish with the same server if the connection drops.
Hashing the URL guarantees a request always hits the cache that already holds its data,
avoiding cache misses and removing the need to duplicate data across every cache.
08
Recap
Balancer = single point of contactFans traffic across a cluster so no machine
overloads; reroutes around dead servers to keep the service up.
Health checks drive routingThe balancer keeps a live list of in-service machines
and only routes to those.
DNS resolves names to IPsResolver โ Root โ TLD โ Authoritative, with heavy
caching (TTL) to stay millisecond-fast.
DNS balancing = round robinAuthoritative server rotates a list of IPs. Cheap and
easy, but ignores load and can route to dead nodes.
Hardware vs. softwareHardware = top performance, costly, specialist-run. Software
(e.g. HAProxy) = cheap, flexible, smarter.
Algorithms beyond round robinWeighted round robin, least connections, random, and
hash (IP for stickiness, URL for cache hits).
๐ก
The single idea underneath it all
Every load-balancing method is the same bet made with better information. Round-robin DNS decides blind; a
software balancer decides with health, load, CPU, and hashing signals. The more the router knows about the
servers behind it, the smarter โ and stickier โ its choice of where your request lands.
09
Further reading
The section cites two external links. Both verified live today.
[1]
Round-robin DNS โ
WikipediaWhy read it: expands Section 05 with the mechanics of A-record rotation and a dedicated
"Drawbacks" section that reinforces exactly why DNS balancing shouldn't be relied on alone (caching, no load
awareness, routing to failed hosts).
[2]
HAProxyWhy read it: the canonical software load balancer named in Section 06 โ the real-world tool
behind the algorithms in this chapter.โ Now a broad enterprise-platform site; the course cited it simply as an example software
balancer.