Skip to main content

DNS (Domain Name System)

Context & Purpose

DNS is the decentralized phonebook of the internet. It translates human-readable hostnames (e.g., google.com) into machine-readable IP addresses (e.g., 142.250.190.46). Without it, we would have to memorize IPs.

Mechanism / Architecture

DNS is a Hierarchical Distributed Database.

Key Concepts

  1. Recursion: The User asks the Resolver to "do the work". The Resolver performs the iterative steps.
  2. Caching: Every step (Browser, OS, Router, ISP) caches the result for a duration defined by TTL (Time To Live). Low TTL = specific traffic control; High TTL = less load.
  3. Hierarchy:
    • Root (.): Managed by ICANN (13 logical server clusters).
    • TLD (.com, .org): Managed by Registries (e.g., Verisign).
    • Authoritative: The actual server holding the records (e.g., Route53, Cloudflare).

Analysis & Trade-offs

Pros

  • Decentralization: No single point of failure for the entire internet.
  • Scalability: Heavy caching at every layer absorbs massive traffic.

Cons

  • Propagation Delay: Changes to records take time to propagate due to caching (TTL).
  • Security: Vulnerable to spoofing (fixed by DNSSEC) and amplification attacks.

Real-world Usage

Common Record Types

RecordPurposeExample
AHostname -> IPv4example.com -> 1.2.3.4
AAAAHostname -> IPv6example.com -> 2001:db8::1
CNAMEHostname -> Hostname (Alias)www.example.com -> example.com
MXMail Serverexample.com -> mail.google.com
NSNameserver Delegationexample.com -> ns1.aws.com

CNAME limitation

Critical: You generally cannot put a CNAME at the "Root" (apex) of a domain (e.g., example.com). You can only use it for subdomains (www.example.com). Cloud providers created "Alias" or "Flattening" records to bypass this restriction.

Interview Check

  1. What happens when you type a URL into the browser?
    • (DNS step): Browser checks cache -> OS cache -> ISP Resolver -> Root -> TLD -> Auth NS.
  2. Why use a CNAME vs an A Record?
    • Use CNAME when you want to alias to another service (like an ELB) whose IP might change. Use A Record when you control the static IP.