Home/Learn/System Design/DNS & Domain Resolution

DNS & Domain Resolution

Beginner
Fundamentals

DNS translates human-readable domain names (api.example.com) into IP addresses. Understanding DNS is essential for system design because it is the first hop of every request and enables load balancing, failover, and service discovery.

Overview

The Domain Name System (DNS) is a hierarchical, distributed database that maps domain names to IP addresses. When a user types "api.example.com", the browser asks a recursive resolver (usually the ISP or a public resolver like 8.8.8.8). The resolver queries root servers → .com TLD servers → the authoritative nameserver for example.com, which returns the IP address. DNS responses are cached at multiple levels (browser, OS, resolver) with a TTL (Time-To-Live). In system design, DNS is used for global load balancing (Route 53 latency-based routing), failover (health-checked DNS records), and service discovery. DNS record types include A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), TXT (verification), and SRV (service location). Low TTLs enable fast failover but increase DNS query load.

DNS Resolution Flow

A full DNS lookup involves the recursive resolver querying root servers, TLD servers, and the authoritative nameserver. Results are cached at every level, so subsequent lookups are much faster.

Conceptual + CLI — DNS resolution flow
// DNS resolution step by step
//
// 1. Browser cache (Chrome: chrome://net-internals/#dns)
// 2. OS cache (macOS: scutil --dns)
// 3. Recursive resolver (ISP / 8.8.8.8 / 1.1.1.1)
//    └─→ 4. Root server (.) → returns .com TLD server
//    └─→ 5. TLD server (.com) → returns authoritative NS for example.com
//    └─→ 6. Authoritative NS → returns A record: 93.184.216.34
// 7. Response cached at resolver (TTL = 300s)
// 8. Response returned to OS → browser → connection to IP

// dig command to inspect DNS
$ dig api.example.com +trace
// Shows each hop: root → .com → example.com → A record

// Common record types:
// A      → IPv4 address          (api.example.com → 1.2.3.4)
// AAAA   → IPv6 address
// CNAME  → alias to another name (www → api.example.com)
// MX     → mail server
// TXT    → verification, SPF, DKIM
// NS     → nameserver delegation

DNS for Load Balancing & Failover

DNS can distribute traffic across regions using weighted, latency-based, or geolocation routing. Health-checked records enable automatic failover when a region goes down.

Conceptual + Terraform — DNS failover
// Route 53 — latency-based routing with health checks
//
// api.example.com
//   ├── A record → 10.0.1.1 (us-east-1, latency routing, health check)
//   └── A record → 10.0.2.1 (eu-west-1, latency routing, health check)
//
// User in India → resolved to lowest-latency region (likely ap-south-1)
// If us-east-1 health check fails → traffic automatically routed to eu-west-1

// Terraform: Route 53 health check + failover
resource "aws_route53_health_check" "primary" {
  fqdn              = "api-us-east.example.com"
  port              = 443
  type              = "HTTPS"
  request_interval  = 10
  failure_threshold = 3
}

resource "aws_route53_record" "api_primary" {
  zone_id        = var.zone_id
  name           = "api.example.com"
  type           = "A"
  set_identifier = "primary"
  failover_routing_policy { type = "PRIMARY" }
  alias { name = aws_lb.primary.dns_name }
  health_check_id = aws_route53_health_check.primary.id
}

Key Points to Remember

  • 1DNS is hierarchical: root → TLD → authoritative nameserver, with caching at every level.
  • 2TTL controls how long DNS responses are cached — lower TTL = faster failover but more DNS queries.
  • 3DNS-based load balancing (weighted, latency, geo) is the first layer of global traffic management.
  • 4Health-checked DNS records enable automatic regional failover.
  • 5DNS propagation delays mean changes are not instant — plan for TTL expiry during migrations.

Interview Questions

Sign in to ask Aria
1

Walk me through what happens when you type a URL in the browser.

EasyTCS
2

How does DNS-based load balancing work?

EasyInfosys
3

What is the trade-off between low and high DNS TTL?

MediumAmazon
4

How would you design DNS for a multi-region active-active setup?

MediumGoogle
5

How does DNS impact the failover time of your system?

HardNetflix

Ask Aria about DNS & Domain Resolution

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…