Skill — DNS Architecture
When this skill activates
Any task involving DNS-based traffic management, load balancing via DNS,
failover strategies, GeoDNS routing, service discovery using DNS,
or TTL optimization for high-availability systems.
Mandatory actions when this skill is active
Before writing any code
- Map the DNS resolution chain (client → resolver → authoritative → response).
- Identify failover requirements (RTO target determines TTL).
- Decide routing strategy (round-robin, weighted, latency, geo, failover).
- Determine health check mechanism for DNS-managed endpoints.
During implementation
- Set TTL appropriate to failover speed requirements.
- Implement health checks for all DNS-managed endpoints.
- Use anycast for latency-critical global services.
- Configure both primary and secondary DNS providers for resilience.
- Document propagation delays for operational runbooks.
- Never rely on DNS as sole load balancer for sub-second failover.
After implementation
- Verify health checks remove unhealthy endpoints within TTL window.
- Test failover scenario end-to-end (kill primary, measure recovery time).
- Confirm GeoDNS routes correctly from each target region.
- Monitor DNS resolution latency and error rates.
- Validate TTL behavior in major resolvers (Google, Cloudflare, ISP).
DNS Load Balancing
Strategies
| Strategy |
How It Works |
Best For |
| Round-robin |
Rotate through A records |
Simple distribution |
| Weighted |
Assign weight per endpoint |
Canary, capacity differences |
| Latency-based |
Route to lowest-latency endpoint |
Global services |
| Failover |
Primary/secondary with health check |
HA with clear primary |
| Geo |
Route by resolver geography |
Data sovereignty, latency |
Limitations
- DNS caching means changes take TTL seconds to propagate.
- Client-side caching may ignore TTL (some browsers cache 60s minimum).
- Cannot do sub-second failover via DNS alone.
- Resolver location != user location (use EDNS Client Subnet to improve).
GeoDNS
How It Works
- DNS query arrives at authoritative server.
- Server determines resolver's geographic location (via IP geolocation).
- Returns IP address of nearest datacenter.
- EDNS Client Subnet (ECS) improves accuracy by passing client subnet.
Configuration
# Example GeoDNS policy
api.example.com:
default: us-east-1.api.example.com
EU: eu-west-1.api.example.com
APAC: ap-southeast-1.api.example.com
fallback: us-east-1.api.example.com # if region unhealthy
Considerations
- Resolver location != user location (corporate DNS, VPN users).
- ECS support improves accuracy but not universally supported.
- Always have fallback for unresolvable regions.
- Test from each target region to verify correct routing.
TTL Strategy
TTL Decision Framework
| Scenario |
Recommended TTL |
Reason |
| Fast failover needed |
30-60 seconds |
Quick removal of unhealthy |
| Normal operation |
300 seconds (5 min) |
Balance between freshness and cache |
| Static content CDN |
3600 seconds (1 hour) |
Rarely changes, maximize cache |
| During migration |
60 seconds |
Prepare for cutover |
| After migration stable |
300-3600 seconds |
Return to normal caching |
TTL Trade-offs
- Low TTL (30s): Fast failover, more DNS queries, higher authoritative load.
- High TTL (3600s): Fewer queries, better cache hit rate, slow failover.
- Strategy: Lower TTL before planned changes, raise after stability confirmed.
Propagation Reality
- TTL expiry != instant propagation.
- Some resolvers enforce minimum TTL (30s-60s).
- Browser DNS cache may ignore TTL entirely.
- Java apps cache DNS indefinitely by default (set
networkaddress.cache.ttl).
Service Discovery via DNS
Internal Service Discovery
- Use internal DNS zone (e.g.,
service.internal).
- SRV records provide port discovery alongside host.
- Short TTL (5-15s) for dynamic service registration.
SRV Records
_http._tcp.api.internal. 15 IN SRV 10 100 8080 api-pod-1.internal.
_http._tcp.api.internal. 15 IN SRV 10 100 8080 api-pod-2.internal.
Kubernetes DNS
- Service discovery built-in:
service-name.namespace.svc.cluster.local.
- Headless services return individual pod IPs.
- ExternalName services alias external endpoints.
Anycast DNS
How It Works
- Multiple servers advertise the same IP address via BGP.
- Network routes traffic to the nearest server (by BGP path).
- If one server goes down, BGP re-routes to next nearest.
Use Cases
- Authoritative DNS servers (Cloudflare, Route53).
- CDN edge nodes.
- DDoS mitigation (absorb attack across multiple PoPs).
Considerations
- Failover speed depends on BGP convergence (seconds to minutes).
- TCP connections break on route change (DNS is UDP, so usually fine).
- Not suitable for stateful protocols without session persistence.
Health Checks
DNS Health Check Pattern
- Health checker probes endpoints at regular intervals (10-30s).
- If endpoint fails N consecutive checks, remove from DNS response.
- Continue probing. If endpoint recovers, add back after M consecutive successes.
- Removal takes effect within TTL seconds (resolver cache expiry).
Health Check Types
| Type |
Checks |
Use For |
| TCP |
Port open |
Basic availability |
| HTTP |
Status 200 + body match |
Application health |
| HTTPS |
Valid cert + status |
Full stack health |
| Custom |
Business logic probe |
Application-specific |
Timing
- Check interval: 10-30 seconds.
- Failure threshold: 2-3 consecutive failures.
- Recovery threshold: 2-3 consecutive successes.
- Effective failover time: check_interval × failure_threshold + TTL.
Self-check
1---2name: dns-architecture3description: Skill — DNS Architecture4---56# Skill — DNS Architecture78## When this skill activates9Any task involving DNS-based traffic management, load balancing via DNS,10failover strategies, GeoDNS routing, service discovery using DNS,11or TTL optimization for high-availability systems.1213## Mandatory actions when this skill is active1415### Before writing any code161. Map the DNS resolution chain (client → resolver → authoritative → response).172. Identify failover requirements (RTO target determines TTL).183. Decide routing strategy (round-robin, weighted, latency, geo, failover).194. Determine health check mechanism for DNS-managed endpoints.2021### During implementation22- Set TTL appropriate to failover speed requirements.23- Implement health checks for all DNS-managed endpoints.24- Use anycast for latency-critical global services.25- Configure both primary and secondary DNS providers for resilience.26- Document propagation delays for operational runbooks.27- Never rely on DNS as sole load balancer for sub-second failover.2829### After implementation30- Verify health checks remove unhealthy endpoints within TTL window.31- Test failover scenario end-to-end (kill primary, measure recovery time).32- Confirm GeoDNS routes correctly from each target region.33- Monitor DNS resolution latency and error rates.34- Validate TTL behavior in major resolvers (Google, Cloudflare, ISP).3536## DNS Load Balancing3738### Strategies39| Strategy | How It Works | Best For |40|----------|-------------|----------|41| Round-robin | Rotate through A records | Simple distribution |42| Weighted | Assign weight per endpoint | Canary, capacity differences |43| Latency-based | Route to lowest-latency endpoint | Global services |44| Failover | Primary/secondary with health check | HA with clear primary |45| Geo | Route by resolver geography | Data sovereignty, latency |4647### Limitations48- DNS caching means changes take TTL seconds to propagate.49- Client-side caching may ignore TTL (some browsers cache 60s minimum).50- Cannot do sub-second failover via DNS alone.51- Resolver location != user location (use EDNS Client Subnet to improve).5253## GeoDNS5455### How It Works561. DNS query arrives at authoritative server.572. Server determines resolver's geographic location (via IP geolocation).583. Returns IP address of nearest datacenter.594. EDNS Client Subnet (ECS) improves accuracy by passing client subnet.6061### Configuration62```63# Example GeoDNS policy64api.example.com:65 default: us-east-1.api.example.com66 EU: eu-west-1.api.example.com67 APAC: ap-southeast-1.api.example.com68 fallback: us-east-1.api.example.com # if region unhealthy69```7071### Considerations72- Resolver location != user location (corporate DNS, VPN users).73- ECS support improves accuracy but not universally supported.74- Always have fallback for unresolvable regions.75- Test from each target region to verify correct routing.7677## TTL Strategy7879### TTL Decision Framework80| Scenario | Recommended TTL | Reason |81|----------|----------------|--------|82| Fast failover needed | 30-60 seconds | Quick removal of unhealthy |83| Normal operation | 300 seconds (5 min) | Balance between freshness and cache |84| Static content CDN | 3600 seconds (1 hour) | Rarely changes, maximize cache |85| During migration | 60 seconds | Prepare for cutover |86| After migration stable | 300-3600 seconds | Return to normal caching |8788### TTL Trade-offs89- **Low TTL (30s)**: Fast failover, more DNS queries, higher authoritative load.90- **High TTL (3600s)**: Fewer queries, better cache hit rate, slow failover.91- **Strategy**: Lower TTL before planned changes, raise after stability confirmed.9293### Propagation Reality94- TTL expiry != instant propagation.95- Some resolvers enforce minimum TTL (30s-60s).96- Browser DNS cache may ignore TTL entirely.97- Java apps cache DNS indefinitely by default (set `networkaddress.cache.ttl`).9899## Service Discovery via DNS100101### Internal Service Discovery102- Use internal DNS zone (e.g., `service.internal`).103- SRV records provide port discovery alongside host.104- Short TTL (5-15s) for dynamic service registration.105106### SRV Records107```108_http._tcp.api.internal. 15 IN SRV 10 100 8080 api-pod-1.internal.109_http._tcp.api.internal. 15 IN SRV 10 100 8080 api-pod-2.internal.110```111112### Kubernetes DNS113- Service discovery built-in: `service-name.namespace.svc.cluster.local`.114- Headless services return individual pod IPs.115- ExternalName services alias external endpoints.116117## Anycast DNS118119### How It Works120- Multiple servers advertise the same IP address via BGP.121- Network routes traffic to the nearest server (by BGP path).122- If one server goes down, BGP re-routes to next nearest.123124### Use Cases125- Authoritative DNS servers (Cloudflare, Route53).126- CDN edge nodes.127- DDoS mitigation (absorb attack across multiple PoPs).128129### Considerations130- Failover speed depends on BGP convergence (seconds to minutes).131- TCP connections break on route change (DNS is UDP, so usually fine).132- Not suitable for stateful protocols without session persistence.133134## Health Checks135136### DNS Health Check Pattern1371. Health checker probes endpoints at regular intervals (10-30s).1382. If endpoint fails N consecutive checks, remove from DNS response.1393. Continue probing. If endpoint recovers, add back after M consecutive successes.1404. Removal takes effect within TTL seconds (resolver cache expiry).141142### Health Check Types143| Type | Checks | Use For |144|------|--------|---------|145| TCP | Port open | Basic availability |146| HTTP | Status 200 + body match | Application health |147| HTTPS | Valid cert + status | Full stack health |148| Custom | Business logic probe | Application-specific |149150### Timing151- Check interval: 10-30 seconds.152- Failure threshold: 2-3 consecutive failures.153- Recovery threshold: 2-3 consecutive successes.154- Effective failover time: check_interval × failure_threshold + TTL.155156## Self-check157- [ ] TTL set appropriate to failover speed requirement.158- [ ] Health checks configured for all DNS-managed endpoints.159- [ ] Failover tested end-to-end (measured recovery time).160- [ ] GeoDNS verified from target regions.161- [ ] Secondary DNS provider configured for resilience.162- [ ] Propagation delays documented in runbook.163- [ ] Client-side DNS caching behavior accounted for.164- [ ] Monitoring in place for resolution latency and errors.