How to do regional DNS like a CDN does?

I guess this question could be entitiled, how do CDN's work at the DNS level but the real problem I have is that my company has datacenters in three continents and we have to have europe.example.com us.example.com and asia.example.com

CDN's typically send you to the local datacenter I imagine depending on your IP address. This must be a DNS thing where you have the DNS server in USA send you to a USA datacenter for the same example.com DNS lookup?

Am I wrong? If I am wrong about this, how would I do this effectively and if possible without central (non DNS) servers?


Solution 1:

The trouble with CDNs is that they don't direct you based on your own IP address - they direct you based on the IP address of your DNS server... That could be completely wrong. And do read Paul Vixie's ACM article, it's bang on the money.

Anyhow, if you've already got region.example.com set up and running, you could consider doing an HTTP redirect from example.com to the relevant webserver, based on the client's IP address.

That's pretty much what Google does, it's how I end up at google.co.uk having typed in google.com.

Do also ensure though that you provide a means for clients to get to the other variations. Clients don't like it when they're forced to a particular site, whether by mistakes in the Geo databases or simply because they actually need to see the site from another region.

Solution 2:

Newer CDNs (Cloudflare, MaxCDN, fast.ly) use anycast for both DNS and actual content servers. This is somewhat better than trying to use the source IP of a DNS query and an ever changing mapping database.

In theory using anycast for both the DNS and content servers allows the network itself to find the "closest" servers to the client. In practice, this is mostly true, but some weird cases arise where people in Singapore will hit edge servers in California instead of Hong Kong due to the ever-changing peering relationships between ISPs.

Anycast is difficult to do well.

Older CDN like Akamai and Limelight generally use anycast to get you to the closest DNS server, but then take the guess-based-on-source-IP approach. This doesn't work as well in my experience, especially if a client is using DNS severs that aren't actually nearby in terms of network topology. However, a huge established CDN like Akamai has hundreds of content server locations, so returning a "close enough" answer results in a decent user experience. Obviously, having hundreds of sites is very expensive, which is why none of the all-anycast CDNs chose that route. Consequently, They also don't charge as much for mostly-equivalent service.