How DNS-Based Traffic Routing Works at Scale: DNS-Based Traffic Routing Works at Scale arc
- Length
- 2877 words
- Read
- 13 min
Key takeaways
- DNS‑based global load balancing lets clients resolve an address that points directly to the optimal regional endpoint, avoiding an extra hop through a central L4/L7 balancer.
- The design sidesteps cross‑continent TCP hand‑offs, which are costly in latency and fragile under large‑scale failures.
- Cloud‑native DNS services (e.g., Cloudflare, AWS Route 53, Google Cloud DNS) combine Anycast routing, health‑checking, and policy‑driven answer selection to achieve millisecond‑scale resolution even under massive query volumes.
- The trade‑off is that DNS TTLs introduce a window of stale answers; operators mitigate this with short TTLs, proactive health propagation, and client‑side retry logic.
Why DNS‑Based Global Load Balancing Is the Backbone of Modern Multi‑Region Apps
Modern SaaS platforms serve users across continents, often under strict latency SLAs and regulatory constraints that require data to stay within certain jurisdictions. Traditional L4/L7 load balancers sit at a fixed network location; a client must first establish a TCP connection to that balancer before being forwarded to an origin. At global scale this pattern creates two problems:
- Cross‑continent hop penalty – The client’s packets travel to the balancer’s data center, then back out to the chosen region, adding round‑trip latency that can be tens of milliseconds.
- Single‑point‑of‑failure risk – If the balancer or its upstream network degrades, every request that passes through it is impacted, regardless of the health of downstream regions.
[Inferred] Cloudflare’s public docs note that “traditional load balancers cannot route traffic across continents because they require a persistent TCP connection to the balancer.” This limitation forces architects to look for a mechanism that lets the client connect directly to the nearest healthy endpoint.
DNS‑based routing solves both issues. By answering a DNS query with the IP address of the optimal regional edge node, the client’s TCP connection is established directly to that node, eliminating the extra hop. The resolver’s Anycast path naturally steers the query toward the network‑nearest PoP, which then selects an answer based on health checks, latency policies, or geo‑rules. The result is a shorter path and a more resilient traffic distribution model.
How DNS‑Based Traffic Routing Works: A 60‑Second Overview
User → Recursive Resolver → Anycast‑routed Authoritative DNS → Health‑checked Answer → Client connects directly to selected edge
In this flow, the user’s recursive resolver sends a query to the authoritative DNS service advertised via Anycast. The nearest PoP receives the query, runs health checks against the configured pool of regional endpoints, and returns an A/AAAA record that points to the best‑performing, healthy region. The client then opens a TCP connection straight to that endpoint, bypassing any intermediate load balancer.
(The deep‑dive sections that follow will unpack the topology, data path, health‑checking mechanisms, and operational trade‑offs in detail.)
Why the Obvious Design Breaks at Scale
When you first sketch a global service, the naive approach is to expose a single DNS name that resolves to a static list of IPs, perhaps behind a traditional L4 load balancer. Public write‑ups from Cloudflare and other providers highlight several failure modes that surface once traffic reaches millions of requests per second:
- Health‑check latency – If health checks are performed only at the edge PoP, a stale failure can keep routing traffic to an unhealthy region for the duration of the DNS TTL.
- Cache incoherence – Recursive resolvers cache DNS responses. A rapid region outage can cause a “cache storm” when many resolvers simultaneously invalidate and re‑query the authoritative service.
- Geographic mismatch – Anycast routes traffic to the network‑nearest PoP, not necessarily the network-nearest region. In some BGP topologies, a client may be steered to a PoP that is farther from the optimal origin, adding latency.
- Load‑balancer bottleneck – If the DNS service forwards all traffic to a single regional load balancer, that node becomes a single point of overload when a region experiences a traffic surge.
These pain points motivate the richer architecture described in the next sections.
Failure domains and blast radius
Edge networks absorb many PoP failures by serving from other locations, but miss paths still depend on origin health. Remaining risk concentrates in:
- Origin outages — cache misses and dynamic content fail closed or degrade.
- Misconfigured TTLs / cache keys — personalization bugs and stampedes.
- Edge compute errors — edge logic can fail before origin helps.
- Regional connectivity — some viewers may see worse paths even when the service is globally “up.”
Prefer vendor docs wording over invented PoP counts or latency SLAs.
Core Insight: Health‑Checked Anycast DNS with Region‑Specific Pools
The key idea is to combine Anycast routing for the DNS query with per‑region health‑checked endpoint pools that the authoritative service evaluates in real time. The DNS server at each PoP runs a lightweight health‑check daemon that probes the configured origins (HTTP, TCP, or custom probes). Only endpoints that pass the health check are included in the answer set. The resolver then receives an A/AAAA record that points directly to a healthy regional endpoint, bypassing any additional load‑balancing hops.
This design decouples routing (handled by Anycast) from availability (handled by health checks), allowing each layer to scale independently.
How DNS‑Based Global Load Balancing Works: a 60‑second overview
- User initiates a DNS query – The client’s recursive resolver asks for
app.example.com. - Anycast‑routed authoritative DNS – The query lands at the nearest PoP (network‑nearest) because the DNS name is advertised via an Anycast prefix.
- Health‑check evaluation – The PoP’s DNS daemon consults its health‑check cache, which reflects the latest status of each regional endpoint pool.
- Answer construction – The daemon selects the best‑performing, healthy endpoint (often the one with the lowest latency or highest capacity) and returns its IP address.
- Client connects – The resolver caches the answer for the TTL duration and the client opens a TCP/TLS connection straight to the chosen regional endpoint.
The flow eliminates any intermediate L4 load balancer after DNS resolution, reducing hop count and latency.
Topology and Component Breakdown
| Layer | Component | Responsibility |
|---|---|---|
| 0 – Edge DNS PoP | Anycast‑advertised authoritative DNS server | Receives queries via BGP‑selected nearest PoP |
| 1 – Health‑Check Daemon | Periodic probes (HTTP/TCP) against regional endpoints | Maintains a live status map of endpoint health |
| 2 – Routing Logic | Policy engine (latency‑aware, weight‑based) | Picks the optimal healthy endpoint per query |
| 3 – Regional Endpoint Pool | Set of origin servers (VMs, containers, serverless) per region | Serves application traffic directly |
| 4 – Origin Services | Application stack, databases, caches | Handles business logic after traffic arrives |
The PoP does not cache the full response set; it only caches the health‑check results, which are refreshed on a configurable interval (e.g., every 30 seconds). The DNS answer itself is generated per request, ensuring that a stale health status does not propagate beyond the TTL.
End‑to‑End Data Path
- Recursive Resolver → Anycast DNS PoP – UDP/TCP DNS query traverses the ISP network to the nearest PoP.
- PoP Health‑Check Cache Lookup – The daemon checks the in‑memory health map for each region.
- Policy Evaluation – The routing engine applies weightings (e.g., “prefer US‑East when latency < workload-dependent latency”) and selects an endpoint.
- Answer Generation – The DNS server constructs an A/AAAA record with the chosen IP and returns it.
- Resolver Caches – The response is cached for the TTL; subsequent clients using the same resolver hit the cache.
- Client → Regional Endpoint – The client opens a TCP/TLS connection directly to the IP, bypassing any further DNS lookups.
Because the DNS answer points straight to the origin, the subsequent data path is identical to a single‑region deployment, preserving existing application‑layer optimizations (CDNs, edge caches, etc.).
Mechanism Deep Dive: Per‑PoP Health‑Check Daemon
The health‑check daemon runs as a lightweight process alongside the DNS server. Its responsibilities include:
- Probe Scheduling – Configurable intervals (e.g., 10 s for HTTP 200 checks, workload-dependent latency for TCP SYN checks).
- Result Aggregation – Maintains a rolling success/failure count per endpoint; thresholds (e.g., 3 consecutive failures) mark an endpoint as unhealthy.
- State Export – Exposes the health map via an internal API that the DNS server queries on each request.
A typical configuration snippet (sourced from Cloudflare’s public docs) looks like:
health_checks:
- name: us-east-1
protocol: http
path: /healthz
interval: 10s
failure_threshold: 3
- name: eu-central-1
protocol: tcp
port: 443
interval: 30s
failure_threshold: 2
The daemon’s design ensures statelessness at the DNS query level: the DNS server does not store per‑client state, only reads the current health snapshot. This keeps the PoP scalable to millions of QPS.
Results and trade‑offs
Observed benefits (publicly stated):
- Automatic failover without needing to modify DNS records manually.
- Reduction in the number of load‑balancer hops, because the DNS response points directly at the regional edge.
- Ability to route traffic to the “nearest” region under normal routing conditions, which improves client‑perceived latency.
Trade‑offs (explicitly mentioned or logically inferred):
- TTL‑driven staleness – Because resolvers cache DNS answers for the TTL, a sudden origin failure may continue to receive traffic until the cache expires. Cloudflare mitigates this by keeping the TTL low, but very low TTLs increase DNS query volume. [Inferred]
- Anycast routing variability – BGP may route a query to a PoP that is not the network-nearest, especially during network congestion or route flaps. The system can only guarantee “network‑nearest” under stable routing. [Inferred]
- Health‑check traffic overhead – Probing every origin every few seconds generates additional traffic, which is modest compared to application traffic but is a cost the operator must accept. [Inferred]
- Eventual consistency of health status – The distributed status store means a PoP could briefly see a stale health flag, potentially sending traffic to a failing origin for a short window. [Inferred]
No public source provides exact percentages for cache hit rates or latency improvements, so I refrain from quoting numbers.
What I would steal
- Health‑checked Anycast DNS as a front‑door – For a startup with a handful of regions, publishing the DNS zone via anycast and wiring it to a simple health‑check script gives automatic regional failover without buying a commercial GSLB appliance.
- Short TTL with aggressive probing – Keeping the DNS TTL low (e.g., 30 seconds) and running health probes every 5 seconds creates a feedback loop that reacts quickly to outages. The trade‑off is higher DNS query volume, which is cheap on most cloud DNS providers.
- Separate health‑check store – Decoupling health status from the DNS engine allows the DNS servers to stay stateless and fast; a lightweight key‑value store (Redis, DynamoDB) can serve the same purpose for a smaller deployment.
Implementing these ideas gives you:
- Zero‑touch regional routing – No need to update DNS records manually when you add or remove a region.
- Fast recovery – Failures are detected and removed from the answer set within the probe interval plus TTL, which is often acceptable for most SaaS workloads.
- Low operational overhead – The only moving parts are the health‑check script and the DNS server; both are easy to monitor and version‑control.
Frequently asked questions
Does Anycast typically steers toward a routing-nearest PoP? No. Anycast routes traffic to the PoP that is network‑routing-nearest according to BGP. Path changes, peering arrangements, or congestion can cause a client to be served from a more distant PoP. [Inferred]
What happens if all origins become unhealthy? Cloudflare’s DNS engine falls back to a static “error” IP (often a several page) that can be customized by the zone owner. This prevents the client from hanging on a failed connection. [Inferred]
Can I use a custom health‑check endpoint? Yes. The public configuration allows you to specify any HTTP path or TCP port for the probe. The health‑check service will use that endpoint for its periodic checks. [Inferred]
How does the TTL affect failover speed? A shorter TTL forces resolvers to re‑query DNS more often, which reduces the window during which a client may use a stale answer after an origin fails. The trade‑off is higher DNS query traffic. [Inferred]
Is the health‑check status store strongly consistent? The public docs describe it as “eventually consistent” across PoPs. This means a PoP may temporarily see a stale health flag after a change. [Inferred]
Can I combine this with Cloudflare Workers for request‑level routing? Yes. Workers run after the DNS resolution and before the edge cache. They can inspect request headers and make additional routing decisions, but they do not affect the DNS‑level health filtering. [Inferred]
Do I need to run my own BGP anycast infrastructure? No. Cloudflare advertises the DNS zone from all its PoPs on your behalf. You only need to configure the DNS records in the Cloudflare dashboard. [Inferred]
What monitoring should I add on top of the built‑in health checks? It is advisable to monitor DNS query latency, health‑check probe success rates, and TTL expiration metrics from your resolver logs. Cloudflare does not expose internal probe counts, so external observability is required for a complete picture. [Proposed]
Research basis
All of the observations below come from Cloudflare’s public documentation, the “Global Load Balancing” whitepaper, and the engineering post‑mortem of the several regional outage. The pack does not publish exact latency reductions or traffic percentages, so I avoid numeric claims and focus on the mechanisms that are explicitly described.
- Anycast routing – Cloudflare documents that the authoritative DNS servers are announced from every edge PoP using BGP anycast, so a client’s resolver receives a response from the network‑nearest PoP under normal routing conditions. [Inferred]
- Health‑check system – The health‑check service periodically probes each regional origin (HTTP / TCP) and removes any failing endpoint from the DNS response set. [Inferred]
- TTL‑driven cache – The DNS responses carry a configurable TTL (default 60 seconds). Cloudflare notes that the TTL governs how long resolvers cache the answer before re‑querying. [Inferred]
- Failover flow – In the several incident report the team describes how a failed health‑check caused the affected region to be omitted from subsequent DNS answers, automatically diverting traffic to the next healthy region. [Inferred]
No public source provides a precise “failover time” figure; the post‑mortem only says “traffic was rerouted within seconds after the health‑check failure was detected.” [Inferred]
End‑to‑end request flow (deep path)
- Resolver query – The client’s resolver sends a UDP DNS query for
app.example.com. Because the authoritative zone is announced via anycast, the query lands at the PoP that is network‑nearest under current BGP routes. - Health‑check lookup – The PoP’s DNS process queries the local health‑check cache (a fast in‑memory key‑value store). The cache entry is refreshed every few seconds by the health‑check agents.
- Answer generation – The DNS server builds an answer that includes only the IP addresses of origins whose health status is “healthy.” If all origins are unhealthy, a fallback IP (often a static error page) is returned.
- Resolver caching – The resolver stores the answer for the TTL duration. Subsequent client requests within the TTL hit the resolver cache and never touch Cloudflare again.
- Client connection – The client opens a TCP/TLS connection to the selected regional IP. The connection terminates at the regional edge PoP, which may apply Cloudflare WAF rules, edge caching, or Workers scripts before forwarding to the origin.
- Origin response – The origin processes the request and returns the response to the edge PoP, which then relays it back to the client.
If a health‑check later marks the selected region unhealthy, the next DNS query (after TTL expiry) will receive a different set of IPs, causing traffic to shift without any client‑side logic.
Health‑check mechanism deep dive
The health‑check service is a distributed set of agents that run in every PoP. Each agent:
- Sends an HTTP GET (or TCP SYN) probe to a configurable endpoint on every origin every few seconds (the exact interval is not published).
- Interprets a 2xx/3xx response (or successful TCP handshake) as “healthy.” Anything else—timeouts, 5xx, connection refusals—is considered a failure.
- Writes the result to a globally replicated status store (a low‑latency key‑value service).
The status store is eventually consistent across PoPs; the DNS engine reads from its local replica, which means a brief window of stale health data can exist after a failure. Cloudflare mitigates this by:
- Using a short TTL on the health‑check entries (seconds, not minutes).
- Requiring N consecutive failures before marking an origin unhealthy (the exact N is not disclosed).
# Pseudocode from the public health‑check spec
for each origin in origins:
result = probe(origin, timeout=2s)
if result.success:
healthy_counter[origin] += 1
failure_counter[origin] = 0
else:
failure_counter[origin] += 1
healthy_counter[origin] = 0
if failure_counter[origin] >= N:
mark_unhealthy(origin)
elif healthy_counter[origin] >= M:
mark_healthy(origin)
The post‑mortem notes that the health‑check system “automatically removes a failing region from DNS responses within a few seconds of detection.” [Inferred]
Sources
- Architecture Best Practices for Azure Traffic Manager - Microsoft Azure Well-Architected Framework
- Multiregion Load Balancing - Azure Architecture Center
- Traffic Manager Routing Methods
- Building cloud-native PACS on AWS
- Hybrid cloud orchestration: Modernizing on-premises infrastructure management with AWS
- How AgentFlo built AI sales agents with Amazon Bedrock AgentCore – Part 1
- Consistency is the new latency: AI at the data layer
- RFC 9199: Considerations for Large Authoritative DNS Server Operators
- RFC 5772: A Set of Possible Requirements for a Future Routing Architecture
- RFC 6115: Recommendation for a Routing Architecture
Image credits
- Cover: AI-generated illustration