DNS (Domain Name System) in Distributed Systems

The Domain Name System (DNS) is the internet’s globally distributed directory that translates human-readable domain names (like tymbits.com) into machine-routable IP addresses (like 104.21.x.x). Beyond simple name lookup, DNS is the very first routing layer in almost every large-scale architecture — steering users to the nearest CDN edge, distributing traffic across regional load balancers, and enabling multi-region failover.

How DNS Resolution Works Step by Step

When you type tymbits.com into a browser and the answer is not already cached locally, a recursive resolver (run by your ISP or a public provider like Cloudflare 1.1.1.1 or Google 8.8.8.8) walks the DNS hierarchy on your behalf:

DNS recursive resolution flow: Browser asks Recursive Resolver for tymbits.com; Resolver queries Root Server for .com TLD NS, queries .com TLD Server for Authoritative NS, queries Authoritative NS for IP 104.21.x.x, and returns the cached IP to the Browser DNS recursive resolution flow: Browser asks Recursive Resolver for tymbits.com; Resolver queries Root Server for .com TLD NS, queries .com TLD Server for Authoritative NS, queries Authoritative NS for IP 104.21.x.x, and returns the cached IP to the Browser
Step-by-step DNS resolution: the recursive resolver walks Root → TLD → Authoritative nameservers, then caches the IP for its TTL · Made with Akriti
  1. Local cache check: The browser and OS check their in-memory DNS cache (and /etc/hosts). If a fresh entry exists, no network call happens.
  2. Recursive resolver query: On a cache miss, the client asks its configured recursive resolver (1.1.1.1, 8.8.8.8, or ISP resolver). If the resolver already cached tymbits.com for another user, it replies immediately in ~5 ms.
  3. Root nameserver (.): If uncached, the resolver asks one of the 13 logical Root clusters (backed by hundreds of Anycast servers worldwide). The root doesn’t know tymbits.com, so it replies with the nameservers responsible for .com.
  4. TLD nameserver (.com): The resolver asks the .com Top-Level Domain server, which replies with the Authoritative Nameservers configured for tymbits.com (for example, Cloudflare DNS or AWS Route 53).
  5. Authoritative nameserver: The authoritative server holds the actual DNS zone records and returns the IP (104.21.x.x) along with a TTL (Time to Live) in seconds.
  6. Cache and return: The resolver caches the record for the TTL duration and returns the IP to the browser, which then opens a TCP/TLS connection to that IP.

Common DNS Record Types

Record Maps From → To Typical Use Case
A Hostname → IPv4 address Pointing api.example.com to a load balancer IPv4
AAAA Hostname → IPv6 address Dual-stack IPv6 support alongside A records
CNAME Hostname → Another hostname Aliasing www.example.com to a CDN or SaaS domain (not allowed at zone apex without CNAME flattening/ALIAS)
NS Domain → Authoritative nameservers Delegating a domain or subdomain to a DNS provider
MX Domain → Mail server + priority Routing inbound email (SMTP)
TXT Domain → Arbitrary text Domain ownership verification, SPF, DKIM, and DMARC email security
SRV Service name → Host + port Internal service discovery (Kubernetes CoreDNS, Consul)

DNS as a Distributed Traffic Router

Modern managed DNS providers (Route 53, Cloudflare, NS1) don’t just return one static IP — they dynamically compute answers per query:

  • Round-Robin DNS: Returns multiple A records in rotating order to spread load across several entry points. Simple, but clients cache one IP for the full TTL and DNS itself doesn’t know per-server load.
  • GeoDNS / Latency-Based Routing: Returns the IP of the data center geographically closest (or lowest RTT) to the caller’s resolver, dramatically reducing latency for global users.
  • Weighted Routing: Sends, say, 95% of answers to the stable cluster and 5% to a canary region during rollouts.
  • Active Health-Checked Failover: The DNS provider probes each regional load balancer and stops returning unhealthy IPs when a region goes down.
  • Anycast DNS: Providers advertise the same IP from hundreds of global PoPs via BGP so every DNS query automatically lands at the nearest server.

Caching, TTL, and Failover Pitfalls

DNS scales to billions of queries per second because it relies heavily on multi-layer caching (browser → OS → router → recursive resolver). That same caching creates classic operational trade-offs:

  • High TTL (e.g., 3600s–86400s): Fewer authoritative lookups and lower DNS cost, but if an origin IP dies, users keep hitting the dead IP until cached entries expire.
  • Low TTL (e.g., 30s–60s): Faster failover and blue-green cutovers, but higher query volume and more frequent cold-lookup latency.
  • Stubborn caches: Some ISPs and older JVMs ignore very short TTLs (or cache DNS forever unless configured). Never treat DNS alone as instant millisecond failover — pair it with regional load balancers and Anycast CDNs.
  • AP-leaning design: In CAP theorem terms, DNS strongly favors Availability and eventual consistency — stale answers during propagation are preferred over failing lookups globally.

FAQs

Why does DNS use UDP by default instead of TCP? Standard DNS queries and responses are tiny (typically under 512 bytes) and fit in a single UDP packet, avoiding the 3-way TCP handshake overhead. DNS automatically falls back to TCP when responses exceed UDP limits (such as large DNSSEC payloads), for zone transfers (AXFR), or when using encrypted DNS-over-HTTPS (DoH) / DNS-over-TLS (DoT).
What is the difference between a CNAME and an ALIAS / ANAME record? A standard CNAME cannot be placed at a zone apex (like tymbits.com) because RFC rules forbid mixing CNAME with SOA/NS records. ALIAS / ANAME (or Cloudflare’s CNAME flattening) resolves the target hostname on the authoritative server and returns a plain A/AAAA record to clients, making apex-to-CDN routing work seamlessly.
Why does changing a DNS record take time to ‘propagate’? DNS doesn’t actively push changes across the internet. Instead, recursive resolvers around the world continue serving the old cached record until its TTL expires, at which point they query the authoritative nameserver again. Lowering the TTL 24 hours before a planned migration makes the cutover finish in minutes.
How is DNS used inside Kubernetes or microservices? Inside Kubernetes, CoreDNS acts as an internal authoritative DNS server mapping service names like payment.default.svc.cluster.local to stable virtual ClusterIPs (or pod IPs via headless services) — forming the backbone of server-side service discovery.