4. DNS
4.6 How can DNS spread users across servers or send them to the nearest one?
In your phone's contacts: A big company gives one helpline number, but the call is connected to the nearest branch. And if one branch is closed, you're sent to another.
In the system: Because the authoritative server chooses the answer, DNS can do simple traffic steering.
Round-robin DNS: give one name several A records. Different users get the list in a different order and mostly connect to the first.
- Simple and free.
- But DNS isn't a load balancer. It doesn't know which server is busy or dead, and caches keep handing out a dead server's IP until the TTL runs out. Clients also don't spread perfectly.
GeoDNS (geographic routing): the authoritative server answers based on where the question comes from.
Figure: one name, two answers. Each user is sent to the region closest to them.
- The "where" is usually the resolver's location, not the user's. A user in Mumbai using a resolver in Singapore may be routed as if they were in Singapore. An extension called EDNS Client Subnet lets resolvers pass along part of the user's network address to fix this, where supported.
Health-checked DNS failover: managed DNS services can check your servers and stop handing out the IP of one that's down. With a short TTL, most users move within minutes.
In practice: DNS picks the region (or the nearest set of load balancers), and real load balancers (Chapter 7) spread traffic inside the region. Many large sites also use anycast, where the same IP address is announced from many locations and the network itself delivers you to the nearest one. CDNs (Chapter 26) rely heavily on both.
Memory code: "DNS picks the city; the load balancer picks the counter." And DNS can't see a dead server until the TTL runs out.