Part 7 of 9 · 3 min read
DNS balancing and geo balancing
Spreading load before a request reaches any balancer, and sending users to the nearest region.
Think of a company with offices in several cities. A caller dials one number, and the phone system connects them to the nearest office. The caller never chooses.
The simplest balancing needs no balancer at all. The book shows it: place several server addresses under one DNS name, and clients pick one when they resolve the name. This works, but it does not deal with failure. If one server goes down, DNS keeps giving out its address. Removing the address by hand takes effect slowly, because DNS answers are cached for their TTL (page 1).
A worked example. A name has a TTL of 300 seconds. A server fails, and its address is removed from the record at once. Copies of the old answer remain in caches for up to 300 seconds, 5 minutes. For up to 5 minutes, some users are still sent to a dead address.
This is why DNS balancing is usually used for a coarse job: choosing between a few strong balancers or regions. The balancers then handle fast failover.
Geo load balancing
Geo load balancing is DNS that looks at the location of the asking client, guessed from its address, and returns the address of the nearest healthy region.
Example: a user in Mumbai asks for shop.example.com and gets the address of the Singapore region. A user in Frankfurt gets the address of the Ireland region.
The book gives the reason from page 1: no server is fast enough to beat distance. A client on the other side of the world sees over 100 milliseconds of delay from the speed of light alone, and more errors on long internet paths. So traffic is spread over data centres in several regions, and DNS sends each client to the nearest one. The geo system also has to know each region's spare capacity and health, so that an overloaded or dead region is skipped.
A worked example. A shop has users in three regions. Round trips to a single central server are 30, 160 and 240 milliseconds. A first page needs DNS 40 ms and 3 round trips (made up).
| Region | One central server | Regional server (round trip 20 ms) |
|---|---|---|
| A | 40 + 3 × 30 = 130 ms | 40 + 3 × 20 = 100 ms |
| B | 40 + 3 × 160 = 520 ms | 100 ms |
| C | 40 + 3 × 240 = 760 ms | 100 ms |
Regions B and C gain 420 and 660 milliseconds. Region A gains little, so a regional server there is not a priority.
Putting it together, a typical front end looks like this:
User
| (1) geo DNS picks the nearest region
v
[ Region: layer 4 LB ] -> [ layer 7 LBs / reverse proxies ] -> [ web servers ]
Common mistake
Assuming geo DNS gives perfect proximity. It guesses location from the address of the resolver that asked, which may not be near the user. Treat it as a good first guess, not a guarantee.
Check yourself:
- Why can DNS balancing keep sending users to a dead server?
- In the table, why does region A gain less than the others?