DNS in System Design Interviews: When to Use It and What to Say
When an interviewer asks you to design a globally reachable service, DNS is often the first piece of the puzzle. It is the service that turns a name like api.example.com into an IP address that a client can connect to. In a design interview you need to explain why DNS matters, how it works, and what trade-offs you consider when you rely on it.
What Problem DNS Solves
Clients need a stable, memorable identifier for a service, but the underlying machines can change – new instances spin up, old ones are retired, and traffic may be shifted between regions. DNS provides a level of indirection: the name stays the same while the IP address mapping can be updated without touching client code. This decouples deployment from consumption and lets you scale or move servers without a coordinated rollout.
How DNS Works – Step by Step
- Client Resolver – The operating system has a stub resolver that receives the name to resolve.
- Recursive Resolver – The stub forwards the query to a recursive resolver (often your ISP’s DNS server). The resolver checks its cache; if the answer is fresh, it returns it immediately.
- Root Hints – If the answer is not cached, the resolver contacts a root server, which returns the authoritative name-servers for the top-level domain (e.g.,
.com). - TLD Server – The resolver asks the
.comname-servers for the NS records ofexample.com. The TLD server replies with the authoritative servers forexample.com. - Authoritative Server – Finally the resolver queries one of those servers for the A (or AAAA) record of
api.example.com. The server returns the IP address and a TTL (time-to-live). - Caching – The resolver stores the answer for the TTL duration. Subsequent queries hit the cache, avoiding the full lookup chain.
Worked Example
Imagine a user in Tokyo opens https://api.example.com. Their device sends a DNS query to the local recursive resolver. The resolver has no cached entry, so it contacts a root server, then the .com TLD server, and finally the authoritative server for example.com. The authoritative server sees that the query came from a resolver in Japan and, using latency- or geography-based routing, answers with the IP of the load balancer in Japan, with a TTL of 300 seconds. The resolver caches the answer and returns it to the client, which then connects directly to the nearest backend.
Classic Design Questions Where DNS Appears
| Design Question | Where DNS Appears | Why It Matters |
|---|---|---|
| Content Delivery Network (CDN) | At the edge, mapping cdn.example.com to the nearest PoP IP. | Enables low-latency delivery by directing users to the closest cache. |
| Multi-region Web Service | In the DNS tier that resolves api.example.com to region-specific load balancers. | Allows traffic steering and failover across data centers. |
| Service Discovery for Microservices | When a service registers a DNS SRV record (e.g., service.internal). | Provides dynamic discovery without a separate registry. |
In each case, DNS is the first hop that decides which physical machines the request will hit.
Trade-offs and the Alternative Interviewer May Probe
| Aspect | DNS Strength | DNS Weakness | Typical Alternative |
|---|---|---|---|
| Latency | Cached answers make most queries fast (sub-millisecond). | First-time lookups traverse multiple hops, adding ~50-100 ms. | Direct client-side service registry (e.g., Consul) that skips the recursive resolver. |
| Consistency | TTL controls how quickly changes propagate; you can tune it. | Short TTLs increase query load on authoritative servers; long TTLs delay updates. | Push-based configuration updates (e.g., Envoy xDS) that instantly refresh endpoints. |
| Failure Isolation | DNS can return fallback IPs (e.g., secondary data center). | If the authoritative servers are down, lookups start failing as cached answers expire. | Client-side fallback logic that retries alternative endpoints. |
| Scalability | Hierarchical caching spreads load globally. | Authoritative servers must handle the aggregate query rate; over-provisioning may be needed. | Centralized service mesh control plane that routes traffic without DNS. |
Interviewers often follow up with questions like “What if the DNS TTL is too long for a rapid failover?” or “How would you handle a DNS-based DDoS attack?” Be ready to discuss adjusting TTLs, using health-checked load balancers, and adding rate-limiting on authoritative servers.
30-Second Pitch
"DNS is the global name-to-IP directory that lets us keep a stable service name while moving machines around. In a design you place DNS at the edge, cache answers in recursive resolvers, and use short TTLs to enable quick failover. The trade-off is between latency of first lookups and the freshness of routing information; alternatives like a push-based service registry can reduce lookup latency but add complexity."
Common Mistakes Candidates Make
- Treating DNS as a data store – DNS is for routing, not for storing large blobs of configuration. Overloading it with many records can hurt performance.
- Ignoring TTL implications – Stating a fixed TTL without explaining how it impacts failover or cache load shows a shallow understanding.
- Skipping the recursive resolver – Some candidates jump straight to the authoritative server, forgetting that most queries are answered from cache.
- Assuming DNS is instant – Forgetting the extra hop latency for cold lookups can lead to unrealistic latency budgets.
- Not addressing DNS security – Missing mentions of DNSSEC, query amplification attacks, or how to mitigate spoofing leaves a gap in the design.
How to Practice This
- Study the worked design – In the System Design AI library, find the DNS-focused design board and walk through each step.
- Sketch your own flow – Use the canvas to draw the DNS resolution chain for a service you invent, labeling caches, TTLs, and fallback regions.
- Run a mock interview – Explain the DNS piece aloud in 30 seconds, then answer follow-up questions about TTL tuning and failure modes.
Questions people ask
Does DNS replace a service registry?
No. DNS provides name resolution and basic load balancing, but a registry offers richer health checks, versioning, and real-time updates that DNS cannot deliver.
How long should a TTL be for a production service?
It depends on your failover speed requirements. A common compromise is 60–300 seconds: short enough to react quickly, long enough to keep resolver load reasonable.
What is DNSSEC and should I mention it?
DNSSEC adds cryptographic signatures to DNS records to prevent spoofing. Mention it when the interviewer asks about security or integrity of name resolution.
Can DNS be a bottleneck for high-traffic services?
Yes, especially the authoritative servers. Mitigate by using globally distributed Anycast, aggressive caching, and load-balanced name-servers.