Browser workflow from downloading resources to rendering the page part 1
Explore the browser workflow from downloading resources to rendering the page
November 14, 2024Understanding the DNS resolution process
When we enter a URL in the browser, the browser will resolve the domain name to an IP address, this process is called DNS resolution. But how does the browser resolve the domain name to an IP address? Here is the process:
Step 1: Check browser DNS cache
If the browser has cached the result, it will return the cached immediately, but the cache will expire/cleaned after a certain period of time or when the browser is closed. Normally, the browser has its own DNS cache mechanism.
Step 2: Check OS DNS cache
If the browser doesn't have the result in its DNS cache, it will check the OS DNS cache. This cache is shared by all applications on the OS, life cycle is longer than the browser's DNS cache.
Step 3: Query ISP DNS server
If there's no result in step 1 and 2, the browser will query the ISP DNS server, in this stage, the ISP DNS server will recursively query the DNS server of the domain name, it will go through the following DNS servers:
Step 3.1: Root DNS server
- Root DNS server is the root zone of the DNS hierarchy. There're 13 root DNS servers worldwide.
- It stores all TLD (Top-Level Domain) DNS server addresses, for example: .com, .net, .org, etc.
- It tells the browser which TLD DNS server to query.
Reference: Root Servers
Step 3.2: TLD DNS server
- It manages all the DNS records of the TLD, for example: .com, .net, .org, etc.
- It stores the second level of DNS server addresses under the TLD, for example: .com has a.iana-servers.net, b.iana-servers.net, c.iana-servers.net, etc.
Step 3.3: Authoritative DNS server
- It responsible for final DNS resolution.
- It stores the DNS records of the domain name, for example: www.google.com has 172.217.14.206 as its IP address.
- It tells the browser the IP address of the domain name.
Summary
When we enter a URL in the browser, there're several steps to resolve the domain name to an IP address:
- Check browser DNS cache, if there's no result, go to step 2.
- Check OS DNS cache, if there's no result, go to step 3.
- Query ISP DNS server, it will go through (recursively) root DNS server, TLD DNS server and Authoritative DNS server to get the IP address of the domain name, then update cache.
- Return the IP address to the browser.
Vocabulary
- DNS: Domain Name System
- ISP: Internet Service Provider
- TLD: Top-Level Domain