DNS in System Design

Learn how DNS resolution works, how TTLs and record types affect failover, and how DNS is used for geo routing and load distribution.

Beginner · about 2 hours · difficulty 2/5

Learn first: Client-Server Model and How the Internet Works

DNS turns names like api.example.in into IP addresses. It is also one of the first levers you have for routing users and surviving outages.

How resolution works

The client asks a recursive resolver (your ISP, 8.8.8.8 or 1.1.1.1). If it has no cached answer, it walks the hierarchy: root servers, then the TLD servers for .in or .com, then the domain's authoritative name servers. Answers are cached at every level for the record's TTL.

Record types you will use

  • A / AAAA: name to IPv4 / IPv6 address.
  • CNAME: alias to another name (common for CDNs and managed load balancers).
  • NS: which servers are authoritative for a zone.
  • MX and TXT: mail routing and verification (SPF, DKIM, domain ownership).

DNS as a routing tool

  • Round-robin DNS: return several IPs and let clients spread out. Crude; no health awareness.
  • Geo DNS / latency-based routing: send users in Chennai to the Mumbai region and users in Europe to Frankfurt.
  • Weighted routing: send 5 percent of traffic to a new region for a canary.
  • Health-checked failover: managed DNS (Route 53, Cloudflare) stops returning a dead region's IP.

TTL trade-offs

Low TTLs (30 to 60 s) allow fast failover but cause more lookups. High TTLs reduce load and latency but mean clients keep using a dead IP for longer. Some clients and resolvers ignore TTLs entirely, so DNS failover is never instant.

Pitfalls

  • Relying on DNS alone for fast failover.
  • Forgetting that DNS itself can be a single point of failure; use a provider with anycast and redundancy.

You are ready to move on when you can explain the full lookup chain and choose a TTL for a service that must fail over between regions.

Key concepts

  • Recursive vs authoritative resolvers
  • Record types (A, CNAME, NS, TXT)
  • TTL and caching
  • Geo and latency-based routing
  • Weighted and failover routing
  • Anycast

Mini project

Use dig to trace the full resolution of three domains (dig +trace), note each hop and TTL, and write a one-page plan for routing users of a two-region app using geo DNS with health checks.

Check yourself

Your Mumbai region goes down and DNS failover kicks in, yet some users still fail for 10 minutes. Give two reasons why.

Free resources