System design2 min

DNS Resolution

The Domain Name System (DNS) is often referred to as the "phonebook of the internet." It translates human-readable domain names (like google.com) into IP addresses (like 142.250.190.46) that computers use to identify each other on the network.

How DNS Resolution Works

When you type a URL into your browser, a complex sequence of events occurs in the background to resolve that domain name into an IP address.

Step 1: The Local Cache

Your browser first checks its own cache to see if it has recently resolved this domain. If not, it checks the Operating System's DNS cache.

Step 2: The Recursive Resolver

If the IP address is not found locally, your OS sends a query to a Recursive DNS Resolver (usually provided by your ISP, or a public one like Google's 8.8.8.8 or Cloudflare's 1.1.1.1). This resolver is responsible for tracking down the IP address on your behalf.

Step 3: The Root Nameserver

The recursive resolver starts by querying a Root Nameserver. The root server doesn't know the IP address, but it knows where to find the servers responsible for Top-Level Domains (TLDs) like .com, .net, or .org.

Step 4: The TLD Nameserver

The recursive resolver then queries the appropriate TLD Nameserver (e.g., the .com nameserver). The TLD server knows which Authoritative Nameserver is responsible for the specific domain (e.g., google.com).

Step 5: The Authoritative Nameserver

Finally, the recursive resolver queries the Authoritative Nameserver for the domain. This server holds the actual DNS records (like the A record) for the domain and returns the IP address.

Step 6: Caching and Returning

The recursive resolver receives the IP address, caches it for future use (based on the Time-To-Live or TTL), and returns it to your Operating System, which then passes it to your browser. Your browser can now initiate a connection to the web server!

Types of DNS Records

  • A Record: Maps a domain to an IPv4 address.
  • AAAA Record: Maps a domain to an IPv6 address.
  • CNAME (Canonical Name): Maps an alias name to a true (canonical) domain name.
  • MX (Mail Exchange): Directs email to a mail server.
  • NS (Name Server): Indicates which DNS server is authoritative for a domain.