DNS Resolution Sequence Diagram

Typing www.example.com into a browser triggers a chain of DNS queries before any connection is made. This UML sequence diagram follows one lookup from the laptop's stub resolver through a recursive resolver to the root, the .com TLD and the authoritative server, then shows how caching changes the picture.


1. The Diagram

DNS Resolution of www.example.com (cold cache) iterative queries (RD=0) Stub resolver laptop OS Recursive ISP / 1.1.1.1 Root server a.root-servers.net .com TLD gtld-servers.net Authoritative ns1.example.com A? www.example.com A? www.example.com referral: com. NS A? www.example.com referral: example.com NS A? www.example.com A 93.184.215.14 TTL 300 (AA) recursive caches NS records and the answer for their TTLs A 93.184.215.14
  1. Stub query. The operating system's stub resolver asks its configured recursive resolver for the A record, with Recursion Desired set. The stub does no chasing itself.
  2. Root. With an empty cache the recursive resolver starts at a root server (it ships with their addresses as root hints). The root does not know the answer; it returns a referral to the .com name servers plus their addresses (glue).
  3. TLD. The .com server returns another referral: the NS records for example.com.
  4. Authoritative. ns1.example.com owns the zone and returns the answer with the Authoritative Answer flag and a TTL of 300 seconds.
  5. Cache and reply. The recursive resolver caches every record it learned for its TTL, then answers the stub. Total: four round trips on a cold cache, often 50 to 200 ms.

2. How to Read It

How to Read a UML Sequence Diagram Participant host or role lifeline (time flows down) message / packet reply (dashed) key step error / failure loop / alt / opt combined fragment repeats or branches

Solid arrows are queries, dashed arrows are responses. The yellow arrow is the only recursive query; the blue fragment groups the iterative queries in which each server only points to the next one.

A frequent misunderstanding is that the laptop talks to the root servers itself. It never does: the stub resolver asks one recursive resolver and waits, and only the recursive resolver walks the hierarchy. Tools such as dig +trace imitate that walk from your own machine.

3. Variant: Warm Cache and NXDOMAIN

Warm Cache: Hit and NXDOMAIN cache hit negative answer Stub resolver laptop OS Recursive ISP / 1.1.1.1 Root server a.root-servers.net .com TLD gtld-servers.net Authoritative ns1.example.com A? www.example.com A 93.184.215.14 (cache, TTL 240) A? www.exmaple.com com. NS still cached: skip the root A? www.exmaple.com NXDOMAIN + SOA NXDOMAIN

Within the 300-second TTL the same question is answered from cache with no upstream traffic, and the remaining TTL counts down. A misspelt name still benefits from caching: the resolver already knows the .com servers, so it skips the root. The TLD replies NXDOMAIN with the zone's SOA record, whose minimum field tells the resolver how long to cache the negative answer.

4. Pros, Cons, and When to Use

Pros

Cons

When to use

When not to use

5. As Diagrams-as-Code

Mermaid sequenceDiagram:

sequenceDiagram
    participant Stub as Stub resolver
    participant Rec as Recursive resolver
    participant Root as Root server
    participant TLD as .com TLD
    participant Auth as ns1.example.com
    Stub->>Rec: A? www.example.com (RD=1)
    Rec->>Root: A? www.example.com
    Root-->>Rec: referral com. NS + glue
    Rec->>TLD: A? www.example.com
    TLD-->>Rec: referral example.com NS
    Rec->>Auth: A? www.example.com
    Auth-->>Rec: A 93.184.215.14 TTL 300 (AA)
    Note over Rec: cache records for TTL
    Rec-->>Stub: A 93.184.215.14