You're absolutely right about CDNs using DNS-based geo-routing. The traditional approach of using subdomains (e.g., eu.example.com) creates maintenance overhead and breaks URL consistency. The modern solution is GeoDNS (Geographical DNS), which returns different IP addresses based on the resolver's location.
When implementing regional DNS routing, these are the key components:
- EDNS Client Subnet (ECS) support - passes partial client IP to authoritative servers
- Anycast routing - same IP advertised from multiple locations
- DNS response filtering - modifying responses based on geolocation databases
Here are three practical approaches with code examples:
Option 1: Using AWS Route53
Here's a CloudFormation template snippet for geo-routing:
Resources:
GeoDNSRecord:
Type: AWS::Route53::RecordSet
Properties:
SetIdentifier: "us-east"
Region: "us-east-1"
GeoLocation:
CountryCode: "US"
TTL: 60
Type: "A"
Name: "example.com"
ResourceRecords: ["192.0.2.1"]
Option 2: DIY with Bind9
Configure geoip in named.conf:
view "US" {
match-clients { country_US; };
zone "example.com" {
type master;
file "/etc/bind/zones/example.com.us";
};
};
view "EU" {
match-clients { country_EU; };
zone "example.com" {
type master;
file "/etc/bind/zones/example.com.eu";
};
};
Option 3: Cloudflare Workers (Edge Logic)
JavaScript-based routing at the edge:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const country = request.cf.country
const serverMap = {
'US': 'us-server.example.com',
'GB': 'eu-server.example.com',
'JP': 'asia-server.example.com'
}
return new Response(Redirecting to ${serverMap[country]})
}
Key metrics to monitor:
- DNS resolution time (keep under 100ms)
- TTL values (balance between 1-5 minutes)
- Failover mechanisms (health checks are critical)
Watch out for these issues:
- DNS caching breaking geo-routing
- VPN users getting incorrect routing
- Mobile clients changing locations frequently
For maximum performance:
# BGP configuration snippet for Anycast
router bgp 65530
network 203.0.113.0/24
neighbor 192.0.2.1 remote-as 64512
neighbor 192.0.2.1 route-map ANYCAST out
This creates a true CDN-like experience where the same IP routes to nearest PoP.
When operating infrastructure across multiple continents, the standard approach of creating region-specific subdomains (e.g., europe.example.com, us.example.com) creates significant operational overhead. What we really want is example.com automatically resolving to the nearest datacenter - exactly how CDNs handle global traffic routing.
GeoDNS (also called GeoIP DNS) makes routing decisions based on the resolver's IP address rather than using separate domains. Here's the technical flow:
Client in Germany → Resolver query → Authoritative DNS (sees German resolver IP) → Returns EU server IP Client in Texas → Same query → Authoritative DNS (sees US resolver IP) → Returns US server IP
Option 1: Managed DNS Providers
Services like Amazon Route 53, Cloudflare, or NS1 provide GeoDNS capabilities:
# Route 53 configuration example (CLI format) aws route53 create-health-check --caller-reference $(date +%s) \ --ip-address 203.0.113.1 \ --port 80 \ --type HTTP \ --resource-path /health aws route53 change-resource-record-sets --hosted-zone-id Z1PA6795UKMFR9 \ --change-batch '{ "Changes": [{ "Action": "CREATE", "ResourceRecordSet": { "Name": "example.com", "Type": "A", "SetIdentifier": "eu-west", "GeoLocation": {"CountryCode": "DE"}, "TTL": 60, "ResourceRecords": [{ "Value": "192.0.2.1" }] } }] }'
Option 2: Open Source Solutions
For self-hosted implementations:
- PowerDNS with geoip backend
- Bind9 with GeoIP patch
- gdnsd with GeoIP support
Latency-Based Routing: Some providers offer performance-based routing that measures actual network conditions rather than just geographic proximity.
Failover Handling: Implement health checks to automatically reroute traffic if a region goes down:
# Sample health check endpoint (Node.js) const express = require('express'); const app = express(); app.get('/health', (req, res) => { checkDatabaseConnection() .then(() => res.status(200).send('OK')) .catch(() => res.status(500).send('DOWN')); }); app.listen(3000);
Verify GeoDNS behavior using tools with global test points:
# Using dig from different regions dig +short example.com @8.8.8.8 # Force specific location with Google's DNS dig +short example.com @ns-aws.global-dns.com
Managed services simplify operations but may limit customization. Self-hosted solutions offer full control but require significant DNS expertise.
For most businesses, we recommend starting with Route 53 or Cloudflare's GeoDNS features, then evaluating whether to move to custom solutions as needs grow.