DNS-Based Load Balancing and GeoDNS
Learn how DNS can distribute traffic across servers using round-robin, weighted records, and geographic routing (GeoDNS).
DNS as a Load Balancer
DNS can distribute incoming traffic across multiple servers by returning different IP addresses for the same domain name. This is one of the simplest and most scalable load balancing techniques, operating at the DNS layer before any connection is made.
Round-Robin DNS
The simplest form of DNS load balancing returns multiple A records for a domain, cycling through them in different orders:
example.com. 300 IN A 203.0.113.1
example.com. 300 IN A 203.0.113.2
example.com. 300 IN A 203.0.113.3
Each DNS query receives the same set of IPs but in a rotated order. Clients typically connect to the first IP in the list, naturally distributing traffic across servers.
Limitations: - No health checking -- DNS continues returning IPs of failed servers until records are manually updated. - Uneven distribution -- DNS caching means some servers may receive more traffic than others. - No session persistence -- subsequent requests may go to different servers.
Weighted DNS
Some DNS providers support weighted records, allowing you to control the percentage of traffic each server receives:
# AWS Route 53 weighted routing
example.com -> Server A (weight: 70) -> 70% of queries
example.com -> Server B (weight: 20) -> 20% of queries
example.com -> Server C (weight: 10) -> 10% of queries
This is useful for gradual rollouts (send 10% of traffic to a new server version) or distributing load proportionally to server capacity.
GeoDNS (Geographic Routing)
GeoDNS returns different IP addresses based on the geographic location of the DNS resolver making the query:
Query from US resolver -> Returns US server IP (203.0.113.1)
Query from EU resolver -> Returns EU server IP (198.51.100.1)
Query from Asia resolver -> Returns Asia server IP (192.0.2.1)
This reduces latency by directing users to the nearest data center. Most CDNs (Cloudflare, Akamai, AWS CloudFront) use GeoDNS combined with anycast for optimal routing.
How GeoDNS Determines Location
GeoDNS uses the IP address of the DNS resolver (not the end user) to determine location. With EDNS Client Subnet (ECS), resolvers can forward a portion of the client's IP to authoritative servers for more accurate geographic decisions.
Health-Checked DNS
Advanced DNS providers integrate health checks with DNS responses:
- The DNS provider monitors each server with HTTP checks, TCP probes, or ICMP pings.
- If a server fails health checks, its IP is removed from DNS responses.
- When the server recovers, its IP is added back.
Server A: Healthy -> included in responses
Server B: Down -> excluded from responses
Server C: Healthy -> included in responses
AWS Route 53, Cloudflare, and NS1 all support health-checked routing.
DNS vs Application-Level Load Balancing
| Feature | DNS Load Balancing | Application LB (Nginx, HAProxy) |
|---|---|---|
| Layer | DNS (Layer 7 pre-connect) | TCP/HTTP (Layer 4/7) |
| Health checks | Slow (TTL-dependent) | Fast (sub-second) |
| Granularity | Per-domain | Per-request |
| Session persistence | Difficult | Easy (cookies, sticky sessions) |
| Scale | Global (anycast) | Per-datacenter |
| Cost | Low (DNS provider) | Higher (dedicated infrastructure) |
In practice, most production architectures combine DNS load balancing for global distribution with application-level load balancers within each data center.