Build a DNS Resolver Cache That Honors TTLs and Negative Answers
Last updated: November 29, 2026
Quick Overview
Services resolving AWS endpoints call the resolver on every request, adding latency and occasionally failing during resolver blips. Implement an in-process DNS cache that respects TTLs, caches NXDOMAIN answers briefly, clamps extreme TTLs, and serves stale answers when the upstream is down.
Amazon
November 29, 20260
0
0 solved
Services resolving AWS endpoints call the resolver on every request, adding latency and occasionally failing during resolver blips. Implement an in-process DNS cache that respects TTLs, caches NXDOMAIN answers briefly, clamps extreme TTLs, and serves stale answers when the upstream is down.
Inside AWS, VPC resolvers enforce per-interface query rate limits, and both over-caching and under-caching have caused real outages industry-wide. The interviewer checks DNS fundamentals (TTL, NXDOMAIN, case-insensitivity) and the trade-off between availability and freshness.
What the Interviewer Expects
- Caches positive answers for their TTL
- Caches negative answers for a short, separate TTL
- Clamps TTLs to a sane minimum and maximum
- Normalizes names: lowercase and trailing dot
- Serves stale data within a grace period only when the upstream fails
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- Why might a JVM-based service never pick up a changed IP, and how do you fix it?
- What goes wrong if you cache too long during a failover?
- How would you prefetch popular names before they expire?
- How should the client choose among multiple returned IPs?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
resolve(name)returns a list of IPs or raisesNXDomain.- Respect the record TTL, clamped to seconds.
- NXDOMAIN cached for 30 seconds so typos do not hammer the resolver.
- If upstr...
High-Level Design
Cache entries are (ips or None, expires_at). On a fresh hit, return or raise from cache. On a miss or expiry, call upstream: success stores the answer; NXDOMAIN stores a negative entry and re-raises...