How DNS Actually Works
A deep dive into the journey of a domain name — from your browser to the authoritative server and back.
The question nobody asks
When you type buildwithpiyush.com into your browser and hit Enter, something remarkable happens in milliseconds. Your browser somehow finds the right server among billions of connected devices on the internet.
How?
That’s DNS — the Domain Name System. And it’s one of the most elegant pieces of infrastructure ever built.
What DNS is really doing
DNS is essentially a distributed, hierarchical phone book for the internet. It translates human-readable names like buildwithpiyush.com into IP addresses like 104.21.45.67 that computers actually use to talk to each other.
But unlike a phone book, it’s not stored in one place. It’s spread across thousands of servers around the world in a tree-like structure.
The resolution journey
Here’s what actually happens when you visit a website:
1. Check the cache first
Your browser first looks in its own cache. Already visited the site recently? Done — no DNS lookup needed.
2. Ask the OS resolver
If the browser doesn’t have it, it asks your operating system, which checks its own cache and the /etc/hosts file.
3. Recursive resolver
Still no answer? Your OS asks a recursive resolver — usually provided by your ISP or a public service like 1.1.1.1 (Cloudflare) or 8.8.8.8 (Google).
4. Root name servers
The recursive resolver doesn’t know the answer either, so it asks a root name server. There are 13 sets of these globally. They don’t know where buildwithpiyush.com is, but they know who’s responsible for .com.
5. TLD name servers
The .com TLD server knows which name servers are authoritative for buildwithpiyush.com.
6. Authoritative name server
Finally, the authoritative server — in this case Cloudflare’s nameservers — returns the actual IP address.
The recursive resolver caches this response for the TTL duration and returns the IP to your browser.
Why this matters as a frontend engineer
Understanding DNS is not just trivia. It directly impacts:
- Performance — DNS lookup time adds to your page load. A slow resolver adds 100-300ms before a single byte is fetched.
- Debugging — “Site not loading” is often a DNS propagation issue, not a server issue.
- Deployment — Moving hosts, setting up custom domains, configuring CDNs — all DNS.
Next time you deploy to Cloudflare Pages and add a custom domain, you’ll know exactly what’s happening under the hood.
This is part of my “How The Web Works” series — where I break down the fundamentals of the web, one layer at a time.