MongoDB
Designing a DNS System
Understand how DNS works under the hood — recursive resolution, caching, TTL, authoritative servers, and how to design a custom DNS resolver.
S
srikanthtelkalapally888@gmail.com
Designing a DNS System
DNS (Domain Name System) translates human-readable domain names into IP addresses.
DNS Hierarchy
Root DNS Servers (.)
↓
TLD Servers (.com, .org, .net)
↓
Authoritative DNS Servers (example.com)
↓
Your IP Address
DNS Resolution Flow
1. Browser checks local cache
2. OS checks /etc/hosts
3. Recursive Resolver (ISP/8.8.8.8)
4. Root Server → TLD Server
5. Authoritative Server → IP returned
6. Cached at each layer
Record Types
A → IPv4 address
AAAA → IPv6 address
CNAME → Alias to another domain
MX → Mail server
TXT → Verification, SPF records
NS → Nameserver delegation
SOA → Zone authority record
TTL (Time To Live)
high TTL (86400s): Stable IPs, reduces resolver load
low TTL (60s): Frequent changes, faster propagation
DNS Caching
- Browser cache: 1 min
- OS cache: TTL-based
- Recursive resolver: TTL-based
- Negative cache: NXDOMAIN responses also cached
DNS Load Balancing
# Round-Robin DNS
example.com → 1.2.3.4
example.com → 5.6.7.8
example.com → 9.10.11.12
# GeoDNS: Return closest IP based on resolver location
Designing a Custom DNS Resolver
Incoming query
↓
Cache lookup (Redis)
↓ (miss)
Forward to upstream resolver (8.8.8.8)
↓
Cache result with TTL
↓
Return IP
DNSSEC
Adds cryptographic signatures to DNS records to prevent spoofing.
DNS Amplification Attack
Small query → Large response → DDoS vector. Mitigation: Rate limiting, response rate limiting (RRL).
Conclusion
DNS is the internet's phonebook. TTL tuning, GeoDNS, and caching are key levers for performance and reliability.