Domain Name System (DNS)

By Oleksandr Andrushchenko, Published on

Domain Name System (DNS) is the distributed naming system that translates human-readable domain names into IP addresses that machines can route. In practical system design, DNS often becomes a hidden dependency whose behavior directly impacts availability, latency, and security. An e-commerce checkout failing because a regional DNS resolver cached a stale record for an API endpoint is a realistic and costly production scenario. Understanding DNS beyond basic resolution is essential for engineers designing resilient systems.

DNS is not just a lookup table; it is a globally distributed, cached, and failure-prone system with tunable behavior. Decisions such as TTL values, record types, and provider choice influence incident blast radius and recovery time. A SaaS platform performing a blue-green deployment relies on DNS cutover timing to safely shift traffic between clusters. These characteristics make DNS a first-class design component rather than an afterthought.

DNS Lookup
DNS Lookup

How DNS Resolution Actually Works

DNS resolution is a multi-step process involving recursive resolvers, root servers, TLD servers, and authoritative name servers. Each step introduces latency and caching, which means changes propagate gradually rather than instantly. A mobile client resolving api.example.com may hit a local ISP cache that is several hours behind the authoritative record.

From a system perspective, resolution behavior affects both cold-start latency and failure modes. A low-latency internal service mesh using DNS-based discovery may experience spikes when caches expire simultaneously. An internal Kubernetes service configured with a 5-second TTL can cause a thundering herd of DNS queries during a rollout.

DNS Record Types and Their Design Implications

DNS record types encode different routing and validation semantics, and selecting the wrong type introduces operational friction. A records bind names to IPv4 addresses, while CNAME records introduce indirection that simplifies migrations. A legacy system hardcoding A records for third-party APIs often blocks smooth provider changes.

Advanced record types such as TXT and SRV enable verification and service discovery but require careful tooling. TXT records are commonly used for domain ownership verification and email security policies. A CI pipeline validating SPF and DKIM via TXT records can fail if DNS propagation assumptions are incorrect.

  • Prefer CNAME records for external dependencies to enable painless provider swaps.
  • Use low TTLs only for records expected to change frequently, such as active-active endpoints.
  • Document ownership of TXT records to avoid accidental deletion during domain cleanups.

DNS record types
DNS record types

TTL Strategy and Cache Invalidation

Time To Live (TTL) defines how long resolvers may cache DNS responses, directly impacting change velocity and stability. Short TTLs allow fast failover but increase query volume and dependency on resolver health. A payment API with a 30-second TTL can recover quickly from a region outage but increases DNS traffic during peak hours.

Long TTLs reduce load but slow incident response and migrations. Some resolvers also ignore extremely low TTLs, applying minimum caching policies. A cloud provider outage where DNS failover was delayed because resolvers enforced a 60-second floor illustrates this trade-off.

TTL Strategy Advantages Risks
Low TTL (≤30s) Fast failover, quick migrations Higher DNS load, resolver dependency
Medium TTL (5–10m) Balanced stability and flexibility Slower rollback during incidents
High TTL (≥1h) Minimal DNS traffic Very slow propagation of changes

DNS-Based Load Balancing

DNS load balancing distributes traffic by returning multiple IP addresses or region-specific answers. This approach is simple and highly scalable but lacks real-time health awareness. A global media platform using round-robin DNS may still route users to an unhealthy edge until caches expire.

GeoDNS and latency-based routing improve user experience but depend on resolver location rather than client location. This mismatch can cause suboptimal routing for mobile or corporate VPN users. An enterprise customer behind a centralized resolver may always hit the wrong region despite being geographically distributed.

  • Combine DNS load balancing with application-level health checks.
  • Use weighted records to gradually shift traffic during rollouts.
  • Continuously measure regional error rates to validate routing effectiveness.

DNS in Microservices and Service Discovery

DNS-based service discovery is commonly used in containerized and cloud-native environments due to its simplicity. Systems such as Kubernetes automatically manage DNS records for services and pods. A backend service resolving payments.default.svc.cluster.local abstracts away dynamic pod IPs.

However, DNS is not a real-time discovery mechanism and may lag behind rapid scaling events. Short TTLs mitigate this but introduce overhead. A burst autoscaling event where hundreds of pods start simultaneously can overload the cluster DNS service.

import socket
import time
from typing import Optional


class DNSResolver:
    def __init__(self, retries: int = 3, backoff_seconds: float = 0.5):
        self.retries = retries
        self.backoff_seconds = backoff_seconds

    def resolve(self, hostname: str) -> Optional[str]:
        """
        Resolve a hostname to an IPv4 address with retries.
        Returns the resolved IP or None if resolution fails.
        """
        for attempt in range(1, self.retries + 1):
            try:
                ip_address = socket.gethostbyname(hostname)
                return ip_address
            except socket.gaierror as exc:
                if attempt == self.retries:
                    raise RuntimeError(
                        f"DNS resolution failed for {hostname} after {self.retries} attempts"
                    ) from exc
                time.sleep(self.backoff_seconds)


if __name__ == "__main__":
    resolver = DNSResolver(retries=3, backoff_seconds=0.5)
    ip = resolver.resolve("api.example.com")
    print(f"Resolved api.example.com to {ip}")

Failure Modes and Observability

DNS failures often manifest as application timeouts rather than explicit errors, complicating diagnosis. Resolver outages, expired domains, or misconfigured records can silently break dependencies. An API gateway returning 502 errors because its upstream hostname stopped resolving is a common incident pattern.

Observability requires explicit DNS metrics and logging at the application and infrastructure layers. Tracking resolution latency and failure rates helps identify systemic issues. A spike in DNS lookup time preceding elevated request latency can signal resolver degradation.

  • Instrument DNS lookup duration and error rates in critical services.
  • Alert on unexpected NXDOMAIN or SERVFAIL responses.
  • Maintain runbooks for DNS-related incidents, including registrar access.

Security Considerations in DNS

DNS security is frequently underestimated despite being a common attack vector. Cache poisoning, domain hijacking, and misconfigured records can redirect traffic to malicious endpoints. A compromised registrar account redirecting login.example.com to a phishing server is a real-world breach scenario.

DNSSEC and strict access controls reduce risk but increase operational complexity. DNS changes should follow the same review and audit processes as code changes. A production outage caused by an unreviewed manual DNS edit illustrates the need for change governance.

Control Benefit Cost
DNSSEC Prevents tampering Operational complexity
Registrar MFA Prevents hijacking Administrative overhead
Change Auditing Traceability Slower updates

Design Takeaways

DNS-aware system design treats name resolution as a variable, not a constant. Latency, caching, and failure must be explicitly modeled in architecture decisions. A highly available system that ignores DNS behavior often fails in unexpected and difficult-to-debug ways.
Practical designs balance TTLs, routing strategies, and observability to align with business requirements. DNS choices should be documented alongside load balancing and deployment strategies. A postmortem that explicitly calls out DNS assumptions helps prevent repeat incidents.