Course contentsShow
← System Design
Lesson 116 of 1,9193. Load BalancingFree lesson

DNS-Based Load Balancing

Explore using DNS records for load distribution, understanding TTL implications, geographic routing, and limitations.

DNS-Based Load Balancing

What you'll learn: How DNS records can distribute traffic across servers and the practical limitations of this approach.

The Core Idea

DNS-based load balancing uses the Domain Name System itself to distribute traffic. When a client queries your domain (like api.example.com), the DNS server can return different IP addresses to different clients, spreading requests across multiple servers. Think of it like a phone directory that gives different callers different office locations for the same company.

How It Works

When your DNS responds to a query, it can return multiple IP addresses in a rotating fashion or select IPs based on rules. The client's operating system or browser then picks one to connect to.

TTL Implications

Time To Live (TTL) tells clients how long to cache a DNS response. A short TTL (e.g., 60 seconds) allows faster changes but increases DNS query load. A long TTL (e.g., 3600 seconds) reduces DNS traffic but means clients might use outdated IPs for an hour after you remove a failing server.

Geographic Routing

DNS can examine the client's location and return IPs of nearby servers. A user in Europe might get EU server IPs, while an Asian user gets Asian IPs, reducing latency.

Key Limitations

  • No health awareness: DNS doesn't know if a server is down; clients may receive IPs of failed servers
  • Cache control issues: You can't force clients to refresh cached DNS records
  • Coarse-grained: Works at the connection level, not the request level
  • No session awareness: Can't implement sticky sessions easily

Key Takeaway: DNS-based load balancing is simple and works at the global routing level, but lacks real-time health checks and fine-grained control compared to dedicated load balancers like NGINX or HAProxy.