Nextgen Blog
HomeLearnAIQuantumRoboticsSecuritySpaceAbout
Nextgen Blog

By Anubhav — full stack engineer, IIT Mandi CSE. Deep dives into AI, software engineering, and the technologies shaping the next generation of tech.

Navigate

  • Home
  • Learn
  • Blog
  • Archive
  • About

Topics

  • Artificial Intelligence
  • Quantum Computing
  • Robotics
  • Cybersecurity
  • Space Tech

Connect

Built with ❤️ & By - Anubhav

© 2026 Nextgen Blog by Anubhav. All rights reserved.

Privacy PolicyTerms of Service
Phase 01 · Foundations & Web ArchitectureChapter 5 of 33
04.
Phase 01Read time ~22 minDifficulty advanced

DNS Deep Dive

In this chapter
  • 01What Is DNS?
  • 02Why Do We Need DNS?
  • 03Problem 1 — Human usability
  • 04Problem 2 — IP addresses can change
  • 05Problem 3 — One name can represent multiple destinations
  • 06Problem 4 — Geographic routing
  • 07The DNS Mental Model
  • 08DNS Hierarchy
  • 09Root DNS
  • 10TLD — Top-Level Domain
  • 11Authoritative DNS Server
  • 12Recursive DNS Resolver
  • 13Recursive vs Authoritative
  • 14DNS Resolution — The Big Picture
  • 15Local DNS Caching
  • 16DNS Cache
  • 17TTL
  • 18Why TTL Matters
  • 19DNS Propagation
  • 20DNS Records
  • 21A Record
  • 22AAAA Record
  • 23CNAME Record
  • 24CNAME vs A
  • 25A record
  • 26CNAME
  • 27NS Record
  • 28MX Record
  • 29TXT Record
  • 30SOA Record
  • 31DNS Zones
  • 32DNS Delegation
  • 33Full DNS Lookup Example
  • 34Step 1 — Client asks recursive resolver
  • 35Step 2 — Resolver asks root
  • 36Step 3 — Resolver asks .com
  • 37Step 4 — Resolver asks authoritative server
  • 38Step 5 — Authoritative server returns record
  • 39Step 6 — Resolver caches answer
  • 40Step 7 — Client receives answer
  • 41Recursive vs Iterative Resolution
  • 42Recursive request
  • 43Iterative queries
  • 44DNS Negative Responses
  • 45DNS Load Balancing
  • 46DNS vs Load Balancer
  • 47DNS-Based Failover
  • 48Health Checks
  • 49Geographic DNS Routing
  • 50Anycast
  • 51DNS and CDN Architecture
  • 52DNS Caching Trade-off
  • 53TTL = 60 seconds
  • 54TTL = 86400 seconds
  • 55DNS and Service Discovery
  • 56DNS in Kubernetes
  • 57DNS Security
  • 58DNS over HTTPS
  • 59DNS over TLS
  • 60DNS Does Not Usually Carry Application Data
  • 61DNS Failure Scenario
  • 62DNS Caching and Failure
  • 63DNS as a Control Plane
  • 64Example — Global Application
  • 65Common DNS Mistakes
  • 66Mistake 1 — Thinking DNS always returns an IP immediately
  • 67Mistake 2 — Thinking DNS propagation is a fixed global timer
  • 68Mistake 3 — Thinking DNS is a load balancer
  • 69Mistake 4 — Thinking CNAME directly means "IP address"
  • 70Mistake 5 — Thinking DNSSEC encrypts DNS
  • 71Mistake 6 — Thinking DNS failure always immediately breaks every client
  • 72Interview Questions
  • 73Q1. What is DNS?
  • 74Q2. What is the difference between recursive and authoritative DNS?
  • 75Q3. What happens when you enter example.com?
  • 76Q4. What is TTL?
  • 77Q5. What is an A record?
  • 78Q6. What is an AAAA record?
  • 79Q7. What is a CNAME?
  • 80Q8. What is an NS record?
  • 81Q9. Can DNS be used for load balancing?
  • 82Q10. Why is DNS caching important?
  • 83Practice Exercises
  • 84Exercise 1 — DNS Resolution
  • 85Exercise 2 — Record Types
  • 86Exercise 3 — TTL
  • 87Exercise 4 — DNS Failover
  • 88Exercise 5 — Global Routing
  • 89Mini Project — Build a DNS Learning Simulator
  • 90System Design Connection
  • 91The DNS Mental Model to Remember
  • 92Chapter Summary
  • 93Next Chapter
  • 94Chapter 04 — HTTP & API Design
In this chapter (94 sections)
01What Is DNS?02Why Do We Need DNS?03Problem 1 — Human usability04Problem 2 — IP addresses can change05Problem 3 — One name can represent multiple destinations06Problem 4 — Geographic routing07The DNS Mental Model08DNS Hierarchy09Root DNS10TLD — Top-Level Domain11Authoritative DNS Server12Recursive DNS Resolver13Recursive vs Authoritative14DNS Resolution — The Big Picture15Local DNS Caching16DNS Cache17TTL18Why TTL Matters19DNS Propagation20DNS Records21A Record22AAAA Record23CNAME Record24CNAME vs A25A record26CNAME27NS Record28MX Record29TXT Record30SOA Record31DNS Zones32DNS Delegation33Full DNS Lookup Example34Step 1 — Client asks recursive resolver35Step 2 — Resolver asks root36Step 3 — Resolver asks .com37Step 4 — Resolver asks authoritative server38Step 5 — Authoritative server returns record39Step 6 — Resolver caches answer40Step 7 — Client receives answer41Recursive vs Iterative Resolution42Recursive request43Iterative queries44DNS Negative Responses45DNS Load Balancing46DNS vs Load Balancer47DNS-Based Failover48Health Checks49Geographic DNS Routing50Anycast51DNS and CDN Architecture52DNS Caching Trade-off53TTL = 60 seconds54TTL = 86400 seconds55DNS and Service Discovery56DNS in Kubernetes57DNS Security58DNS over HTTPS59DNS over TLS60DNS Does Not Usually Carry Application Data61DNS Failure Scenario62DNS Caching and Failure63DNS as a Control Plane64Example — Global Application65Common DNS Mistakes66Mistake 1 — Thinking DNS always returns an IP immediately67Mistake 2 — Thinking DNS propagation is a fixed global timer68Mistake 3 — Thinking DNS is a load balancer69Mistake 4 — Thinking CNAME directly means "IP address"70Mistake 5 — Thinking DNSSEC encrypts DNS71Mistake 6 — Thinking DNS failure always immediately breaks every client72Interview Questions73Q1. What is DNS?74Q2. What is the difference between recursive and authoritative DNS?75Q3. What happens when you enter example.com?76Q4. What is TTL?77Q5. What is an A record?78Q6. What is an AAAA record?79Q7. What is a CNAME?80Q8. What is an NS record?81Q9. Can DNS be used for load balancing?82Q10. Why is DNS caching important?83Practice Exercises84Exercise 1 — DNS Resolution85Exercise 2 — Record Types86Exercise 3 — TTL87Exercise 4 — DNS Failover88Exercise 5 — Global Routing89Mini Project — Build a DNS Learning Simulator90System Design Connection91The DNS Mental Model to Remember92Chapter Summary93Next Chapter94Chapter 04 — HTTP & API Design

1. What Is DNS?#

DNS stands for:

Domain Name System

DNS is the distributed naming system that allows applications to use human-readable names such as:

www.example.com

instead of requiring users to remember an IP address.

At the simplest level:

Domain name
     |
     v
    DNS
     |
     v
IP address

For example:

www.example.com
       |
       v
203.0.113.10

The browser can then use the destination address to establish network communication.

DNS is much more than a simple lookup table.

It is:

  • distributed
  • hierarchical
  • cached
  • delegated
  • highly replicated
  • designed to scale globally

Understanding DNS is essential for System Design because DNS can participate in:

  • service discovery
  • traffic distribution
  • failover
  • geographic routing
  • CDN architectures
  • domain management
  • availability strategies

2. Why Do We Need DNS?#

Imagine there were no DNS.

You would have to remember:

203.0.113.10

instead of:

example.com

That creates several problems.

Problem 1 — Human usability#

Names are easier to remember.

Problem 2 — IP addresses can change#

A service may move from:

203.0.113.10

to:

203.0.113.50

Users should not need to change the URL.

Problem 3 — One name can represent multiple destinations#

For example:

example.com
     |
     +----> Server A
     |
     +----> Server B
     |
     +----> Server C

This can support traffic distribution.

Problem 4 — Geographic routing#

A global service can direct users toward different infrastructure based on location or other routing policies.

DNS therefore provides a flexible naming layer between users/applications and network destinations.


3. The DNS Mental Model#

The most useful beginner mental model is:

Human-readable name
        |
        v
       DNS
        |
        v
Network destination

For example:

api.example.com
        |
        v
     DNS lookup
        |
        v
203.0.113.25

But the actual lookup can involve multiple components:

Application
    |
    v
Recursive Resolver
    |
    v
Root DNS
    |
    v
TLD DNS
    |
    v
Authoritative DNS
    |
    v
IP address

Let's understand each component.


4. DNS Hierarchy#

DNS is hierarchical.

A domain such as:

www.example.com

can be viewed as:

www
 |
example
 |
com
 |
.

The final . represents the DNS root.

So conceptually:

.
└── com
    └── example
        └── www

The hierarchy allows DNS to be distributed.

No single server needs to store every domain on Earth.


5. Root DNS#

At the top of the DNS hierarchy are the root servers.

The root does not normally provide the final IP address for:

www.example.com

Instead, it can direct a resolver toward the appropriate top-level domain infrastructure.

Conceptually:

Resolver
   |
   | Where is .com?
   v
Root
   |
   v
TLD information

There are many instances of the root server system distributed globally.

The important idea is:

Root DNS helps the resolver navigate the DNS hierarchy.


6. TLD — Top-Level Domain#

TLD means:

Top-Level Domain

Examples:

.com
.org
.net
.in
.uk
.dev

For:

www.example.com

the TLD is:

.com

The TLD infrastructure knows which authoritative name servers are responsible for domains under that TLD.

Conceptually:

Root
  |
  v
.com TLD
  |
  v
example.com authoritative DNS

7. Authoritative DNS Server#

An authoritative DNS server holds the DNS information for a domain or delegated zone.

For example:

example.com

might have authoritative name servers that know records such as:

www.example.com → 203.0.113.10
api.example.com → 203.0.113.20

The authoritative server is the source that can provide authoritative answers for the zone.

This distinction is extremely important:

Recursive resolver
→ Finds/caches answers
 
Authoritative server
→ Serves authoritative DNS data for its zone

8. Recursive DNS Resolver#

Most end-user devices do not directly walk the complete DNS hierarchy for every lookup.

Instead, they commonly use a recursive resolver.

Conceptually:

Browser
   |
   v
Operating System
   |
   v
Recursive Resolver
   |
   +--> Root
   |
   +--> TLD
   |
   +--> Authoritative

The recursive resolver performs the work of finding the answer and can cache it.

Examples of recursive DNS services include:

  • ISP-provided resolvers
  • enterprise DNS resolvers
  • public recursive DNS services

The important role is:

A recursive resolver obtains DNS answers on behalf of clients.


9. Recursive vs Authoritative#

This is a common interview question.

Recursive Resolver Authoritative Server
Finds answers for clients Holds authoritative zone data
Can cache answers Provides authoritative records
Queries other DNS servers Serves its own zone
Acts on behalf of requester Acts as authority for domain data

Simplified:

Client
  |
  v
Recursive Resolver
  |
  v
Authoritative DNS

10. DNS Resolution — The Big Picture#

Suppose the browser needs:

www.example.com

A simplified resolution process is:

Browser
   |
   v
Local DNS cache
   |
   | miss
   v
Recursive Resolver
   |
   | cached?
   |
   +---- YES → return answer
   |
   +---- NO
          |
          v
        Root
          |
          v
        .com TLD
          |
          v
      Authoritative DNS
          |
          v
      IP address
          |
          v
   Recursive Resolver
          |
          v
        Browser

This is the core DNS flow.


11. Local DNS Caching#

Before querying a remote resolver, the operating system or browser may already have DNS information cached.

Conceptually:

Browser
   |
   v
Local cache
   |
   +---- HIT → IP
   |
   +---- MISS → Resolver

Caching is critical because DNS lookups themselves take time and create network traffic.


12. DNS Cache#

DNS answers can be cached by multiple layers:

Browser
   ↓
Operating System
   ↓
Local / Network Resolver
   ↓
Authoritative DNS

If an answer is cached:

example.com
     |
     v
Cache
     |
     v
IP address

the resolver does not necessarily need to ask the authoritative server again.


13. TTL#

TTL stands for:

Time To Live

A DNS record can specify how long an answer may be cached.

Example:

TTL = 300 seconds

This means a cache can generally retain that DNS answer for the specified TTL before needing to obtain fresh information.

Mental model:

DNS Record
     |
     +---- TTL = 300

After the TTL expires, a resolver may need to refresh the information.


14. Why TTL Matters#

Suppose:

api.example.com
      |
      v
Old Server

You change it to:

api.example.com
      |
      v
New Server

If caches still hold the old answer, clients may continue using the old destination until the cached record expires.

Therefore:

Lower TTL
→ faster changes
→ more DNS queries
 
Higher TTL
→ fewer DNS queries
→ changes can take longer to propagate through caches

This is a classic trade-off.


15. DNS Propagation#

People often say:

DNS propagation takes time.

A more precise explanation is that DNS information can remain cached according to TTLs and caching behavior.

Suppose:

Old IP = A
New IP = B

Different recursive resolvers may have cached:

Resolver 1 → A
Resolver 2 → B
Resolver 3 → A
Resolver 4 → B

for a period of time.

Therefore users may temporarily observe different answers.


16. DNS Records#

DNS supports multiple record types.

The most important for System Design are:

  • A
  • AAAA
  • CNAME
  • NS
  • MX
  • TXT
  • SOA

Let's study them.


17. A Record#

An A record maps a hostname to an IPv4 address.

Example:

example.com → 203.0.113.10

Conceptually:

example.com
     |
     | A
     v
203.0.113.10

Use case:

api.example.com
      ↓
IPv4 destination

18. AAAA Record#

An AAAA record maps a hostname to an IPv6 address.

Example:

example.com
      |
      | AAAA
      v
2001:db8::10

So:

A
→ IPv4
 
AAAA
→ IPv6

A domain can have both.


19. CNAME Record#

CNAME means:

Canonical Name

It creates an alias from one hostname to another hostname.

Example:

www.example.com
       |
       | CNAME
       v
example.cdn-provider.com

The resolver can then continue resolution for the target hostname.

CNAMEs are useful when an application wants a friendly domain name pointing to another hostname managed elsewhere.


20. CNAME vs A#

Example:

A record#

api.example.com
      ↓
203.0.113.10

CNAME#

api.example.com
      ↓
service.provider.com
      ↓
203.0.113.10

The key difference:

A
→ hostname → IPv4 address
 
CNAME
→ hostname → another hostname

21. NS Record#

NS means:

Name Server

It identifies the authoritative name servers for a DNS zone.

Conceptually:

example.com
    |
    +---- NS → ns1.provider.com
    |
    +---- NS → ns2.provider.com

This delegation allows DNS responsibility to be distributed.


22. MX Record#

MX means:

Mail Exchange

It identifies mail servers responsible for receiving email for a domain.

Example:

example.com
    |
    | MX
    v
mail.example.com

MX records are primarily relevant to email systems rather than normal web traffic.


23. TXT Record#

TXT records can store textual information associated with a domain.

They are commonly used for:

  • domain verification
  • SPF-related email configuration
  • DKIM-related configuration
  • other service metadata

Example conceptually:

example.com
   |
   | TXT
   v
"verification=..."

24. SOA Record#

SOA stands for:

Start of Authority

It contains important administrative information about a DNS zone.

It can include information such as:

  • primary name server
  • zone administrator information
  • serial number
  • refresh-related values
  • retry-related values
  • expiration-related values
  • negative caching-related information

You do not need to memorize every SOA field yet.

The important idea is:

SOA contains core administrative information for a DNS zone.


25. DNS Zones#

A DNS zone is an administrative portion of the DNS namespace managed under a particular authority.

For example:

example.com

may be a DNS zone containing:

www.example.com
api.example.com
mail.example.com

A zone can delegate responsibility for subdomains.

For example:

example.com
     |
     +---- dev.example.com
               |
               +---- delegated zone

Zones are a key reason DNS can scale organizationally.


26. DNS Delegation#

Suppose:

example.com

is managed by one organization.

They can delegate:

internal.example.com

to another authoritative DNS service.

Conceptually:

example.com
     |
     +---- NS → DNS provider A
     |
     +---- internal.example.com
                 |
                 +---- NS → DNS provider B

This allows different teams or organizations to manage different DNS portions.


27. Full DNS Lookup Example#

Let's walk through:

api.example.com

Assume there is no cached answer.

Step 1 — Client asks recursive resolver#

Client
   |
   | api.example.com?
   v
Resolver

Step 2 — Resolver asks root#

Resolver
   |
   v
Root

Root directs the resolver toward the .com TLD infrastructure.

Step 3 — Resolver asks .com#

Resolver
   |
   v
.com TLD

The TLD infrastructure identifies the authoritative servers for:

example.com

Step 4 — Resolver asks authoritative server#

Resolver
   |
   v
Authoritative DNS

It asks for:

api.example.com

Step 5 — Authoritative server returns record#

For example:

api.example.com
A
203.0.113.20
TTL 300

Step 6 — Resolver caches answer#

Resolver cache
 
api.example.com
→ 203.0.113.20
→ TTL 300

Step 7 — Client receives answer#

Client
   |
   v
203.0.113.20

The application can now establish the network connection.


28. Recursive vs Iterative Resolution#

These terms are often confusing.

Recursive request#

The client asks the resolver:

Find the answer for me.

Client
  |
  | recursive query
  v
Resolver

The resolver does the work.

Iterative queries#

The resolver can query DNS servers and receive referrals.

Conceptually:

Resolver → Root
Root → "Ask .com"
 
Resolver → .com
.com → "Ask example.com authoritative server"
 
Resolver → Authoritative
Authoritative → Answer

The resolver iteratively follows the DNS hierarchy.


29. DNS Negative Responses#

DNS can also tell a resolver that a name does not exist.

For example:

does-not-exist.example.com

may return a negative response such as:

NXDOMAIN

NXDOMAIN means the queried domain name does not exist.

Negative answers can also be cached according to applicable DNS rules and zone configuration.


30. DNS Load Balancing#

DNS can return multiple addresses.

Example:

api.example.com
 
A → 203.0.113.10
A → 203.0.113.11
A → 203.0.113.12

A resolver/client may receive multiple addresses.

Conceptually:

api.example.com
       |
       +----> Server A
       |
       +----> Server B
       |
       +----> Server C

This can help distribute traffic.

However, DNS-based distribution has important limitations because:

  • answers are cached
  • clients/resolvers may behave differently
  • traffic distribution may not be perfectly even
  • existing connections are not moved simply because DNS changes

DNS load balancing is therefore different from a traditional load balancer.


31. DNS vs Load Balancer#

Consider:

DNS
 |
 +----> Server A
 |
 +----> Server B

versus:

DNS
 |
 v
Load Balancer
 |
 +----> Server A
 |
 +----> Server B

With a load balancer:

  • every request can be actively routed
  • health checks can influence routing
  • traffic distribution can be controlled dynamically

DNS operates earlier in the process:

Name resolution
      ↓
Destination selection
      ↓
Connection
      ↓
Request

Therefore DNS and load balancing solve related but different problems.


32. DNS-Based Failover#

Suppose:

Primary
203.0.113.10

fails.

A DNS-based system may change responses to:

Secondary
203.0.113.20

Conceptually:

Before:
 
example.com
    ↓
Primary
 
After:
 
example.com
    ↓
Secondary

But cached DNS answers mean clients may continue using the old address until caches expire.

Therefore DNS failover is not instantaneous in all cases.


33. Health Checks#

DNS traffic-management systems can use health checks to determine whether destinations are healthy.

Example:

Health Check
     |
     +----> Server A ✓
     |
     +----> Server B ✗

The DNS service can avoid returning unhealthy destinations depending on the provider and configuration.

This can be useful for:

  • failover
  • multi-region routing
  • service availability

34. Geographic DNS Routing#

A global application might have:

US users
   ↓
US infrastructure
 
India users
   ↓
India/Asia infrastructure
 
Europe users
   ↓
European infrastructure

DNS-based traffic management can use geographic or latency-oriented policies to return different destinations.

Conceptually:

                 DNS
                  |
        +---------+---------+
        |         |         |
        v         v         v
       US       Europe     Asia

The goal can be:

  • lower latency
  • regional isolation
  • regulatory requirements
  • disaster recovery

The exact routing capabilities depend on the DNS provider and architecture.


35. Anycast#

Anycast is a networking technique in which the same IP address is announced from multiple network locations.

Conceptually:

              Same IP
                 |
       +---------+---------+
       |         |         |
       v         v         v
     Site A    Site B    Site C

Network routing can direct users toward an appropriate nearby/available location according to routing policies.

Anycast is widely used in large-scale DNS and edge infrastructure.

Important distinction:

DNS
→ name resolution
 
Anycast
→ network routing technique

They can be used together but are not the same thing.


36. DNS and CDN Architecture#

A common global architecture is:

User
  |
  v
DNS
  |
  v
CDN / Edge
  |
  v
Origin

DNS may direct a hostname toward CDN infrastructure.

The CDN then decides which edge location serves the request.

This allows:

User in India
      ↓
Nearby edge
 
User in Europe
      ↓
European edge

The actual routing architecture depends on the CDN provider.


37. DNS Caching Trade-off#

Consider two TTL choices.

TTL = 60 seconds#

Advantages:

  • changes can become visible relatively quickly
  • failover information can refresh sooner

Disadvantages:

  • more DNS queries
  • more dependency on DNS infrastructure

TTL = 86400 seconds#

Advantages:

  • excellent caching
  • fewer DNS lookups

Disadvantages:

  • changes can remain cached for longer

So:

Lower TTL
→ freshness
 
Higher TTL
→ caching efficiency

The appropriate value depends on operational requirements.


38. DNS and Service Discovery#

DNS can also be used inside infrastructure.

Suppose:

payment-service

needs to find:

inventory-service

A service-discovery system may provide a DNS name:

inventory-service.internal

which resolves to an appropriate service endpoint.

Conceptually:

Payment Service
      |
      | DNS
      v
inventory-service.internal
      |
      v
Service destination

Cloud and container environments commonly provide DNS-based service discovery.


39. DNS in Kubernetes#

Kubernetes provides DNS-based service discovery inside clusters.

Conceptually:

Application Pod
      |
      | DNS lookup
      v
service-name
      |
      v
Kubernetes Service
      |
      v
Pods

This means applications can communicate using service names rather than hard-coding pod IP addresses.

This will become especially useful when we later study Kubernetes system design.


40. DNS Security#

DNS itself has security considerations.

Problems can include:

  • DNS spoofing
  • cache poisoning
  • unauthorized domain changes
  • DNS hijacking
  • denial-of-service attacks

One important technology is:

DNSSEC — Domain Name System Security Extensions

DNSSEC adds cryptographic mechanisms that help validate the authenticity/integrity of DNS data.

DNSSEC does not encrypt normal DNS queries.

That distinction is important.


41. DNS over HTTPS#

DoH means:

DNS over HTTPS

Instead of sending DNS queries using traditional DNS transport, the client can send DNS queries through HTTPS.

Conceptually:

Application
    |
    v
HTTPS
    |
    v
DNS resolver

This can provide encrypted transport between the client and the resolver.


42. DNS over TLS#

DoT means:

DNS over TLS

It similarly protects DNS traffic using TLS.

Conceptually:

Client
   |
   | TLS
   v
DNS Resolver

DoH and DoT address transport privacy in different ways.


43. DNS Does Not Usually Carry Application Data#

This distinction is important.

DNS generally helps answer:

Where is this service?

It does not normally carry:

User's complete HTTP response

A simplified architecture:

DNS
 ↓
Find destination
 
HTTP
 ↓
Exchange application data

44. DNS Failure Scenario#

Suppose:

Browser
   |
   X
DNS Resolver

The browser cannot resolve:

api.example.com

Even if the API servers are perfectly healthy, users may still be unable to access the service.

This demonstrates an important System Design principle:

A dependency can become a single point of failure even when the main application is healthy.

DNS infrastructure therefore needs:

  • redundancy
  • distributed infrastructure
  • operational monitoring
  • appropriate caching

45. DNS Caching and Failure#

Caching can actually provide resilience.

Suppose:

Authoritative DNS
      X unavailable

A recursive resolver may still have a valid cached answer:

Resolver cache
      |
      v
Existing DNS answer

Clients can potentially continue resolving the name while the cached record remains valid.

This is one reason caching is such a fundamental distributed-systems technique.


46. DNS as a Control Plane#

A useful advanced mental model:

DNS can act as a control mechanism for deciding where clients should connect.

For example:

example.com
     |
     v
DNS policy
     |
     +----> Region A
     |
     +----> Region B

Changing DNS configuration can change the destinations clients receive.

But DNS is not a real-time request router because caching creates propagation and freshness constraints.


47. Example — Global Application#

Imagine a service deployed in:

India
Europe
USA

Architecture:

                    Users
                      |
                      v
                     DNS
          +-----------+-----------+
          |           |           |
          v           v           v
        India       Europe       USA
          |           |           |
          v           v           v
        Load        Load         Load
       Balancer    Balancer     Balancer
          |           |           |
       App tier    App tier     App tier

DNS may help direct users toward an appropriate region.

Inside each region:

Load Balancer
      |
      +---- App 1
      +---- App 2
      +---- App 3

This gives us a layered architecture:

DNS
 ↓
Region
 ↓
Load Balancer
 ↓
Application

48. Common DNS Mistakes#

Mistake 1 — Thinking DNS always returns an IP immediately#

The result might involve:

  • cached answer
  • CNAME chain
  • IPv4/IPv6 records
  • multiple records
  • negative response

Mistake 2 — Thinking DNS propagation is a fixed global timer#

Different caches can expire at different times.

TTL and resolver behavior matter.


Mistake 3 — Thinking DNS is a load balancer#

DNS can participate in traffic distribution, but it does not provide the same request-level control as a load balancer.


Mistake 4 — Thinking CNAME directly means "IP address"#

A CNAME points to another hostname.

CNAME
→ hostname

An A record maps to IPv4.

A
→ IPv4

Mistake 5 — Thinking DNSSEC encrypts DNS#

DNSSEC provides authenticity/integrity mechanisms.

It is not the same thing as encrypted DNS transport.


Mistake 6 — Thinking DNS failure always immediately breaks every client#

Cached answers may continue to work until their relevant cache lifetime expires.


49. Interview Questions#

Q1. What is DNS?#

A distributed hierarchical naming system that maps names to information such as network destinations.

Q2. What is the difference between recursive and authoritative DNS?#

A recursive resolver obtains answers on behalf of clients and can cache them. An authoritative server provides authoritative records for its zone.

Q3. What happens when you enter example.com?#

At a simplified level:

Client
 ↓
Local cache
 ↓
Recursive resolver
 ↓
Root
 ↓
TLD
 ↓
Authoritative server
 ↓
IP/record

assuming the answer is not already cached.

Q4. What is TTL?#

The time associated with how long a DNS response may be cached before it should be refreshed according to DNS caching rules.

Q5. What is an A record?#

Hostname → IPv4 address.

Q6. What is an AAAA record?#

Hostname → IPv6 address.

Q7. What is a CNAME?#

Hostname → another hostname.

Q8. What is an NS record?#

It identifies name servers responsible for a DNS zone/delegation.

Q9. Can DNS be used for load balancing?#

Yes, DNS can return multiple destinations or use traffic-management policies, but it has caching and control limitations compared with request-level load balancers.

Q10. Why is DNS caching important?#

It reduces lookup latency, network traffic and load on DNS infrastructure.


50. Practice Exercises#

Exercise 1 — DNS Resolution#

Explain this complete flow:

www.example.com

from browser to IP address.

Include:

  • local cache
  • recursive resolver
  • root
  • TLD
  • authoritative server
  • caching

Exercise 2 — Record Types#

Explain the difference:

A
AAAA
CNAME
NS
MX
TXT
SOA

Exercise 3 — TTL#

Suppose:

api.example.com
IP = A
TTL = 300 seconds

At 12

you change the IP to:

B

Explain why some users/resolvers may continue receiving A for a period of time.


Exercise 4 — DNS Failover#

Design:

Primary Region
Secondary Region

using DNS-based failover.

Discuss:

  • health checks
  • TTL
  • caching
  • failure detection
  • limitations

Exercise 5 — Global Routing#

Design a simple architecture for:

Users:
India
Europe
USA
 
Infrastructure:
India
Europe
USA

Explain how DNS could participate in directing users toward regions.


51. Mini Project — Build a DNS Learning Simulator#

Create a small conceptual program that models:

Client
  ↓
Cache
  ↓
Recursive Resolver
  ↓
Authoritative Server

Support:

  • hostname
  • IP address
  • TTL
  • cache hit
  • cache miss
  • expiration

Example:

Lookup:
api.example.com
 
Cache:
MISS
 
Authoritative:
203.0.113.10
 
TTL:
60 seconds
 
Cache:
STORE

Then repeat the lookup:

Lookup:
api.example.com
 
Cache:
HIT
 
Return:
203.0.113.10

After TTL expiration:

Cache:
EXPIRED
 
Query authoritative DNS again

This exercise will make DNS caching behavior concrete.


52. System Design Connection#

DNS is not just an Internet utility.

It can become part of the architecture.

Consider:

                    User
                      |
                      v
                     DNS
                      |
            +---------+---------+
            |                   |
            v                   v
        Region A             Region B
            |                   |
            v                   v
       Load Balancer       Load Balancer
            |                   |
        App Servers         App Servers

Now introduce failure:

Region A
    X DOWN

DNS traffic management may direct new clients toward Region B.

But remember:

DNS caching
    ↓
Not every client immediately receives the new destination

Therefore a production architecture may combine:

  • DNS
  • global traffic management
  • load balancing
  • health checks
  • multiple regions
  • application-level failover

53. The DNS Mental Model to Remember#

Think in layers:

                DNS
                 |
                 v
             Root (.)
                 |
                 v
              TLD
             (.com)
                 |
                 v
        Authoritative DNS
        (example.com)
                 |
                 v
              Record
                 |
        +--------+--------+
        |        |        |
        v        v        v
       A       AAAA     CNAME
        |        |        |
        v        v        v
      IPv4     IPv6    Hostname

And think about caching:

Client
  ↓
Local Cache
  ↓
Recursive Resolver
  ↓
Authoritative DNS

The most important System Design principle is:

DNS provides a scalable naming and delegation layer, but caching means DNS-based routing is not the same as real-time request routing.


54. Chapter Summary#

You should now understand:

  • DNS purpose
  • DNS hierarchy
  • root DNS
  • TLD DNS
  • authoritative DNS
  • recursive resolvers
  • recursive vs iterative resolution
  • DNS caching
  • TTL
  • DNS propagation
  • DNS zones
  • delegation
  • A records
  • AAAA records
  • CNAME
  • NS
  • MX
  • TXT
  • SOA
  • negative responses
  • DNS load balancing
  • DNS failover
  • health checks
  • geographic routing
  • Anycast
  • CDN integration
  • service discovery
  • Kubernetes DNS
  • DNSSEC
  • DNS over HTTPS
  • DNS over TLS
  • DNS failures
  • DNS as a control plane

55. Next Chapter#

Chapter 04 — HTTP & API Design#

Next we move from:

DNS
 ↓
Find the destination

to:

HTTP
 ↓
Actually communicate with the application

We will study:

  • HTTP request/response
  • methods
  • headers
  • status codes
  • cookies
  • sessions
  • authentication
  • REST APIs
  • JSON
  • idempotency
  • pagination
  • filtering
  • sorting
  • API versioning
  • rate limiting
  • retries
  • API gateways
  • API design best practices
  • common API design mistakes
  • system-design interview questions

Finished this chapter?

Mark it as complete to track your mastery.

Previous ChapterChapter 02 — Networking FundamentalsNext ChapterChapter 04 — HTTP & API Design
PrevNext