Bird
Raised Fist0

How DNS Works - Resolution Chain from Browser to IP Address

HLDmediumInterview freq: common
Choose your preparation mode4 modes available
🏗️
How DNS Works - Resolution Chain from Browser to IP Address
Design walkthrough of DNS resolution chain from browser query to IP address response
mediumNetworking and ProtocolsFreq: common
⚙️
Functional Requirements
  • Resolve a domain name (e.g., www.example.com) to its corresponding IP address
  • Support recursive and iterative DNS queries across multiple DNS servers
  • Cache DNS responses at various levels (browser, OS, resolver) to reduce latency
  • Handle different DNS record types (A, AAAA, CNAME, NS, etc.)
  • Support TTL-based cache expiration and refresh
  • Provide fallback mechanisms for failed DNS queries
📊
Non-Functional Requirements
  • Support global scale: ~5 billion daily DNS queries worldwide
  • 99.99% availability for DNS resolution services
  • P99 latency under 100ms for DNS query resolution
  • Handle peak QPS of ~100 million queries per second at root and TLD servers
  • Cache hit ratio target >90% at recursive resolvers to reduce upstream load
❓
Clarifying Questions to Ask
  • What is the expected scale of DNS queries per second for this system?
  • Are we designing the entire DNS hierarchy or focusing on a specific resolver layer?
  • Should the system support both IPv4 and IPv6 address resolutions?
  • What caching layers are in scope (browser, OS, recursive resolver)?
  • Is the focus on latency optimization, availability, or both?
  • How should failures in upstream DNS servers be handled?
Out of Scope
✗ Design of DNSSEC cryptographic validation
✗ DNS zone file management and updates
✗ Implementation of DNS over HTTPS (DoH) or DNS over TLS (DoT)
✗ Design of authoritative DNS server internals
📌
Assumptions
  • Global daily DNS queries: 5 billion
  • Average DNS queries per user per day: 40
  • Average DNS response size: 100 bytes
  • Retention period for logs/metrics: 7 days
⚡
QPS Calculation
write qps5B queries/day ÷ 86400 seconds ≈ 57,870 writes/sec
peak write qpsAssuming 3x peak factor: 57,870 × 3 ≈ 173,610 writes/sec
read qpsDNS is mostly read-heavy; recursive resolvers cache 90% hits, so upstream reads ≈ 10% of total queries: 5B × 0.1 ÷ 86400 ≈ 5,787 reads/sec
💾
Storage Estimate
daily storage5B queries × 100 bytes = 500 GB/day
retention storage500 GB/day × 7 days = 3.5 TB
with replication3.5 TB × 3 replicas = 10.5 TB total
🖥️
Server Estimate
recursive resolver serversAssuming each server handles 10,000 QPS, need 173,610 ÷ 10,000 ≈ 18 servers
authoritative dns serversRoot and TLD servers handle peak 100M QPS; each server handles 1M QPS, so 100 servers needed
🏗️
Architecture Diagram
Architecture Diagram
Browser
  |
  v
OS DNS Cache
  |
  v
Recursive Resolver (e.g., Google Public DNS, Cloudflare 1.1.1.1)
  |
  v
Root DNS Server
  |
  v
TLD DNS Server
  |
  v
Authoritative DNS Server
  |
  v
IP Address Response
🧩
Components
Browser DNS Cache
Cache DNS responses locally to reduce latency and network calls
Why thisBrowser cache uses technologies like Chrome's DNS cache to provide fastest response by avoiding OS or network queries for repeated domains within TTL
Why notRelying only on OS cache (e.g., Windows DNS Client service) increases latency due to extra system calls and misses browser-specific caching policies
OS DNS Cache
System-level cache shared by all applications to reduce redundant DNS queries
Why thisOS cache (e.g., Windows DNS Client, macOS mDNSResponder) reduces network traffic by caching DNS responses for all apps, improving overall system efficiency
Why notSkipping OS cache would increase network load and latency for all applications
Recursive Resolver (e.g., Google Public DNS, Cloudflare 1.1.1.1)
Receives DNS queries from clients, performs iterative queries to authoritative servers, caches results
Why thisRecursive resolvers like Google Public DNS and Cloudflare reduce load on authoritative servers by caching and provide fault tolerance and latency improvements
Why notDirect client queries to authoritative servers would increase latency and load on authoritative infrastructure
Root DNS Server
Top-level DNS server directing queries to appropriate TLD servers
Why thisRoot servers (e.g., operated by ICANN, Verisign) provide global namespace delegation and are highly available and distributed for scale
Why notUsing a centralized root server would create a single point of failure and scalability bottleneck
TLD DNS Server
Handles queries for top-level domains (e.g., .com, .org), directs to authoritative servers
Why thisTLD servers (e.g., Verisign for .com) partition namespace and reduce query scope, enabling scalable delegation
Why notSkipping TLD servers would overload root servers and authoritative servers with all queries
Authoritative DNS Server
Stores DNS records for specific domains and responds with IP addresses
Why thisAuthoritative servers (e.g., domain registrars' DNS servers) provide the definitive answer for domain names, ensuring correctness and freshness
Why notCaching-only servers cannot provide authoritative answers or updates
🔄
Data Flow
1
Browser → OS DNS Cache
Browser checks local cache for domain IP
If cache hit, returns IP immediately, else proceeds
2
OS DNS Cache → Recursive Resolver
OS cache lookup for domain IP
If miss, OS sends query to recursive resolver
3
Recursive Resolver → Root DNS Server
Sends iterative query to root server for TLD info
Caches root server response for TTL duration
4
Recursive Resolver → TLD DNS Server
Queries TLD server for authoritative server info
Caches TLD response to reduce root queries
5
Recursive Resolver → Authoritative DNS Server
Queries authoritative server for domain IP
Caches final IP response with TTL
6
Recursive Resolver → OS DNS Cache
Returns IP to OS cache for local caching
OS caches response for subsequent queries
7
OS DNS Cache → Browser
Returns IP to browser
Browser uses IP to initiate connection

Practice

(1/5)
1. In the hotel booking system, at step 4 of the reservation flow, the Inventory Service checks room availability. What state does the Inventory Service report if the room was reserved moments ago but the Reservation Service has not yet confirmed the booking?
easy
A. The room is marked as available because the reservation is not yet confirmed
B. The room is marked as temporarily unavailable due to a pending reservation lock
C. The room is marked as unavailable only after payment confirmation
D. The room availability status is unknown until the Reservation Service sends a confirmation event

Solution

  1. Step 1: Trace Inventory Service state at step 4

    The Inventory Service relies on confirmed reservation events to update availability. Pending reservations may not yet be reflected.
  2. Step 2: Understand event-driven state updates

    Without confirmation, Inventory cannot mark the room as unavailable. It waits for Reservation Service confirmation events to update state, so availability is unknown until then.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Inventory waits for confirmation events before updating availability [check]
Hint: Inventory updates only after confirmed reservation events [check]
Common Mistakes:
2. You must design a high-throughput OLTP system that requires strong consistency but can tolerate some delay in durability guarantees. Which approach is best suited?
medium
A. Use asynchronous replication with strict serializable isolation but delayed durability
B. Use synchronous replication with immediate durability on commit
C. Use eventual consistency with snapshot isolation and immediate durability
D. Use read uncommitted isolation with synchronous durability

Solution

  1. Step 1: Analyze consistency and durability trade-offs

    Strong consistency requires strict serializable isolation; durability can be delayed to improve throughput.
  2. Step 2: Evaluate replication and isolation options

    Asynchronous replication with strict serializable isolation fits the requirement, allowing durability delay without sacrificing consistency.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Async replication + strict serializable -> strong consistency, delayed durability [check]
Hint: Strong consistency needs strict isolation, durability can lag [check]
Common Mistakes:
3. Without the segment manifest (playlist) update mechanism, what exactly breaks in the adaptive bitrate HLS streaming workflow?
medium
A. Clients will download all bitrate variants simultaneously, wasting bandwidth
B. Clients will fail to discover new segments, causing playback stalls or infinite buffering
C. Clients will continue playing old segments indefinitely without switching bitrates
D. Clients will switch bitrates too frequently, causing playback instability

Solution

  1. Step 1: Role of manifest updates in HLS

    Manifest updates inform clients about new segments and available bitrates, enabling selective fetching.
  2. Step 2: Consequence of missing manifest updates

    Without updates, clients cannot know which segments to fetch next, leading them to request all variants to avoid stalls, wasting bandwidth.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Missing manifest updates cause clients to fetch all variants, wasting bandwidth [check]
Hint: No manifest updates -> clients fetch all bitrates, wasting bandwidth [check]
Common Mistakes:
4. If the distributed priority queue component fails and becomes unavailable, what is the immediate failure mode observed in the task scheduler?
medium
A. Worker nodes block waiting for tasks, causing execution delays and potential timeouts
B. Tasks are silently dropped without retries, causing data loss
C. Tasks continue executing but with incorrect priority ordering
D. The cron scheduler automatically reschedules tasks on all nodes

Solution

  1. Step 1: Understand role of distributed priority queue

    The queue is the source of truth for pending tasks; if unavailable, new tasks cannot be fetched.
  2. Step 2: Analyze failure impact

    Without the queue, tasks submitted may be lost if not persisted elsewhere; workers cannot fetch tasks, so blocking (B) is unlikely if queue is down; cron scheduler (D) does not reschedule tasks automatically.
  3. Step 3: Evaluate silent drops (C)

    Without queue durability, tasks may be lost silently if producers cannot enqueue or retries are not implemented.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Queue failure causes silent task loss without retries [check]
Hint: Queue failure causes silent task loss without retries [check]
Common Mistakes:
5. At 10x traffic scale during a flash sale, which component is most likely to fail first and why?
hard
A. The relational database because it cannot handle 10x write throughput without sharding
B. The API Gateway because it maintains stateful user sessions and cannot horizontally scale easily
C. The cache layer because TTL expiration floods the database with cache misses
D. The inventory service because distributed locking causes contention and latency spikes

Solution

  1. Step 1: Identify stateful components under load

    API Gateway maintains user session state (e.g., WebSocket connections), which are sticky and stateful, limiting horizontal scaling.
  2. Step 2: Compare other components

    Relational DB (A) can be sharded; cache (C) TTL floods are mitigated by pre-warming; inventory locking (D) is optimized with partitioning. API Gateway statefulness causes connection limits and bottlenecks first.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    API Gateway stateful sessions limit horizontal scaling [check]
Hint: Stateful API Gateway limits scaling under 10x load [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard