5 min read
Computer Networking Index
Tier 1 -- Foundations
Tier 2 -- Core Concepts
Tier 3 -- Debugging & Tradeoffs
Computer Networking Index
Tier 1 -- Foundations
Tier 2 -- Core Concepts
Tier 3 -- Debugging & Tradeoffs
DNS Resolution
1. What Is It?
(Domain Name System) is the internet's phone book — it translates human-readable hostnames like api.example.com into IP addresses like 93.184.216.34 that machines can route to. Without it, every application would need to hardcode IP addresses, making deployments brittle (IPs change), configs unmaintainable, and load balancing nearly impossible to implement transparently.
The problem solves: network routing operates on IP addresses, but developers and users think in names. DNS decouples the two. When your service moves to a new host, you update a DNS record — every caller gets the new IP automatically on their next lookup, with no code changes.
Your backend service is running on a VM at IP address 10.0.1.45. You migrate it to a new VM at 10.0.2.88. Which approach best ensures all client services automatically reach the new host without requiring code changes?
2. How It Works
A resolution goes through up to four participants before returning an IP:
- Recursive Resolver — your ISP's or cloud provider's server. It does the work on your behalf and caches results.
- Root Nameserver — knows which nameserver is authoritative for top-level domains (
.com,.io, etc.). - TLD Nameserver — knows which nameserver is authoritative for
example.com. - Authoritative Nameserver — has the actual A/AAAA record mapping
api.example.com→ IP.
Concrete example: When your Node.js service calls fetch("https://api.stripe.com/v1/charges"), the OS calls getaddrinfo("api.stripe.com") before a single byte of is sent. That call may hit the local cache (fast, ~0ms), the recursive resolver (moderate, ~5–20ms), or do a full traversal (slow, ~50–200ms).
A Node.js service makes an HTTP request to an external API. The OS resolver has no cached entry for the hostname, but the recursive resolver does. Approximately how long should you expect the DNS resolution step to take before the HTTP connection can even begin?
3. What SDEs Actually Need to Know
TTL controls staleness. Every record has a TTL (time-to-live) in seconds. After a TTL expires, resolvers re-query. Setting TTL too high means traffic hits an old IP after you migrate. Setting it too low creates resolver load and increased latency on cold paths. Common practice: lower TTL to 60s a day before a migration, then raise it after.
Record types that matter to SDEs:
A— hostname → IPv4AAAA— hostname → IPv6CNAME— hostname → another hostname (used forwww→ apex, or aliases in cloud services)TXT— arbitrary text (used for SPF, DKIM, domain verification)SRV— service + port (used by gRPC , Kubernetes, Consul)
caching layers can fool you. Your app's DNS lookup goes through: JVM/runtime cache → OS /etc/hosts → OS stub resolver → recursive resolver. A change you made may not be visible for minutes even after TTL expires, because each layer has its own cache. In containers, the OS cache is per-container — /etc/nsswitch.conf and /etc/resolv.conf control behavior.
Common errors:
UnknownHostException/NXDOMAIN— the hostname doesn't exist or isn't reachable from this resolver. Check yoursearchdomain in/etc/resolv.conffor Kubernetes pods.SERVFAIL— the upstream resolver failed. Indicates DNS infrastructure issues.- Slow first requests — DNS cache cold start. Mitigate with (resolves once, reuses the connection).
Your team is planning to migrate a backend service to a new set of servers with different IP addresses. The service's DNS records currently have a TTL of 86400 seconds (24 hours). A week before the migration, an engineer suggests lowering the TTL to 60 seconds. What is the primary reason for doing this before the migration, rather than at the time of migration?
4. Tradeoffs & Decisions
TTL too high vs. too low:
- High TTL (3600s+): fewer lookups, faster resolution, but slow failover. Use for stable infrastructure.
- Low TTL (30–60s): fast failover and migration capability, but more resolver load and occasional extra latency. Use when you need quick -based traffic shifting.
CNAME vs. A record:
- CNAME adds one extra lookup hop (CNAME → A). At the zone apex (bare
example.com) you cannot use CNAME — useALIASorANAMErecords if your provider supports them, or an A record. - Cloud load balancers (AWS ALB, GCP HTTPS LB) are typically pointed to via CNAME because their IPs change.
Split-horizon DNS:
- Internal services often have different DNS answers for internal vs. external clients. If
db.internal.example.comresolves to a private IP from inside your but fails externally, that's intentional. Understanding this prevents confusion when debugging from a laptop vs. in-cluster.
Your team is preparing to migrate a web service to a new set of servers and needs the ability to shift traffic quickly between the old and new infrastructure with minimal downtime. Which DNS TTL strategy best supports this requirement, and what is the key tradeoff you accept?
5. Interview Cheat Sheet
Key sentences:
- " translates hostnames to IPs; without it, every service call would require hardcoded IPs that break on migration."
- "A TTL governs how long resolvers cache a record; lowering it before a migration is a standard operational practice."
- " resolution goes through the OS stub resolver, a recursive resolver, and eventually the authoritative nameserver — each layer caches independently."
- "In Kubernetes, each pod has its own
/etc/resolv.confwith a search domain; unqualified names are resolved against the cluster's internal DNS."
Common follow-ups:
Q: What happens if DNS is slow? A: Your app's first connection to any host incurs the lookup latency — typically 1–50ms from cache, up to 200ms on a cold full traversal. Mitigate with (reuses established connections) and DNS pre-fetching at startup.
Q: How does a use DNS? A: CDNs use DNS-based anycast or geo-routing. Your CNAME points to the 's hostname; the CDN's authoritative nameserver returns the IP of the nearest PoP based on the resolver's IP. This is why different users get different IPs for the same hostname.
Q: What is a DNS negative cache? A: When a hostname lookup returns NXDOMAIN ("not found"), resolvers cache that failure for a duration defined by the SOA record's minimum TTL. This means a misconfigured or missing record continues to fail even after you fix it, until the negative cache expires.
Glossary History
Click dotted jargon to save explanations here.
Glossary History
Click dotted jargon to save explanations here.