SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

System design
How a Request Crosses a NetworkIPTCPUDP Routing, streams, and datagramsDNSHTTP Requests and Responses From a hostname to an HTTP response
Networking

DNS

Trace a hostname lookup and predict how long an old DNS answer may be reused.

Lesson goal

Follow a cold lookup from browser to authoritative nameserver, then explain what changes when the answer is cached.

Before you begin — UDP.

Moving a service to another IP address should leave its links usable. The Domain Name System (DNS) lets clients look up records for a name such as api.example.com. An address record tells the client where to connect. Routers then use IP to forward the packets.

Find the name in a URL

Consider https://api.service.example.com:443/v1/users?sort=desc&limit=10#section-2. The hostname in this example is api.service.example.com. DNS can resolve that name to an address. The browser uses port 443 for the connection and sends the path and query to the HTTP server. The fragment #section-2 stays with the browser.

The URL contains a scheme, hostname, port, path, query, and fragment. DNS looks up the hostname.

Follow a lookup with empty caches

  1. The browser or operating system needs an address for the hostname. If it has no usable local answer, it asks its recursive resolver to find one.
  2. With no relevant cached answers or referrals, the resolver asks a root nameserver where it can find information for .com.
  3. The .com nameserver refers the resolver to the authoritative nameservers for example.com.
  4. An authoritative nameserver supplies the address for api.example.com in this example. If it supplies an alias, the resolver follows that name to obtain the address.
  5. The resolver returns its answer to the client and can cache it. The browser can now connect to the service.

The recursive resolver follows root and top-level domain referrals to the authoritative server, caches the address, and returns it to the browser.

The browser asks one resolver for an answer. The resolver makes the individual queries and follows referrals. A resolver with a cached referral can start further along this path.

To inspect a lookup, run nslookup example.com or dig example.com A. In a dig answer row, look for the name, the remaining time in seconds, the record type, and its value. The addresses and times you see can vary. With dig +trace example.com the tool follows referrals itself, which shows a different path from asking a recursive resolver for a cached answer.

Choose the record that answers the question

RecordQuestion it answers
A, AAAAWhich IPv4 or IPv6 address is associated with this name?
CNAMEWhich other name is this one an alias for?
NS, SOAWhich nameservers serve the zone, and what are its administrative details?
MXWhich hosts accept mail for the domain, and in what preference order?
TXT, PTRWhat text has the operator published, or what hostname is listed for a reverse address lookup?

A zone is a part of the DNS namespace administered together. At its top name, called the apex, the zone needs NS and SOA records. A standard CNAME cannot coexist with those records, so an operator can make www.example.com an alias but cannot use a standard CNAME at the example.com zone apex.

Registering a name and serving its records are separate jobs. A registrant registers a domain through a registrar, the registry maintains registrations for its top-level domain, and authoritative nameservers publish the domain’s records.

Predict what a client sees after an address change

An operator changes an A record from 192.0.2.10 to 192.0.2.20. A resolver fetched the old value at 10:00 with a time to live (TTL) of 300 seconds. At 10:02 it can still return the old address. Under normal caching, after 10:05 it needs fresh information to answer again.

A resolver can reuse an address while its TTL remains positive. After expiry it queries again.

A shorter TTL can reduce the period during which old answers are reused. It also sends more lookups upstream. Lowering the TTL at 10:02 cannot retroactively shorten the copy fetched at 10:00. A dynamic DNS service can publish an address change automatically, and existing caches still follow the lifetime of their copies.

Protect a DNS lookup

Conventional DNS commonly uses UDP port 53. If a UDP response is truncated, the requester can retry over TCP port 53 to receive the full answer. A client can also use TCP from the start. DNS transport requirements

DNSSEC lets a validating resolver check the origin and integrity of signed records. DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt the channel between the client and its chosen resolver. The resolver still sees the query. DNSSEC introduction · DoH specification · DoT specification

Check your understanding

One visitor reaches the new service address at 10:02. Another reaches the old address a minute later. How can both lookups succeed?

Compare your reasoning

The visitors can use different caches. A fresh lookup can see the new record while another resolver can still serve a valid cached copy of the old one.

Key Takeaways

  • Name resolution starts with the hostname. The browser handles the other URL components separately.
  • Referrals lead the recursive resolver to the servers that can answer for a zone.
  • TTL bounds ordinary reuse of a particular cached answer. Independent resolvers can see an address change at different times.

How is this lesson?

Previous lesson Routing, streams, and datagramsNext lessonHTTP Requests and Responses
Edit on GitHubReport on GitHub
On this page
%

On this page

Find the name in a URLFollow a lookup with empty cachesChoose the record that answers the questionPredict what a client sees after an address changeProtect a DNS lookupCheck your understandingKey Takeaways