I found this explanation how a CDN works. But there is one thing I don't really understand. Let's assume I setup multiple DNS servers at my location and they use the nameserver domains
dns3.example.com. This DNS servers are able to deliver a server IP depending on the visitors location (ping, geo database, browser language or whatever). Now I update this nameserver settings for my domain
www.example.org at the registry.
Now, the very first request on
www.example.org with an expired TTL tries to resolve the domain. It asks:
- the local .hosts/DNS, if TTL expired:
- the internet providers DNS, if TTL expired:
- the root DNS, if TTL expired:
- my local
But if I understand it correct, the new IP is then added to all these nameserver caches until the TTL expires again. So how is it possible to send other IPs to the visitor depending on his location?
In this answer theandym said the request is "forwarded", but I don't think this is how a CDN works, because "forwarding" means lengthen the transmission way resulting a longer loading time. Or does a CDN require zero TTL for the domain?
Through this question I found Google's document describing how they optimized CDN performance. It did not explain how the CDN works in general, but there were interesting explanations like the following:
Thereafter, whenever a client attempts to fetch content hosted on the CDN, the client is redirected to the node determined to have the least latency to its prefix. This redirection however is based on the prefix corresponding to the IP address of the DNS nameserver that resolves the URL of the content on the client’s behalf, which is typically co-located with the client.
This means Google checks at first the latency of all IP prefixes and defines a DNS resolution table (?) for all available prefixes. And if a visitor has the IP
198.51.100.231 the Google server IP is used, that is set for the prefix
198.51.100.0. But again: How does Google's DNS know which IP the visitor is using? Most visitors resolve Google's domain through their internet provider and by that the resolving is done through those external DNS servers or not?
As an additional example: If I start a DNS resolution for the domain
facebook.com with different online tools (hosted in different countries) it is resolved to different IPs with different domains like:
- 188.8.131.52 Reverse: edge-star-mini-shv-01-frt3.facebook.com
- 184.108.40.206 Reverse: edge-star-mini-shv-01-sea1.facebook.com
- 220.127.116.11 Reverse: edge-star-mini-shv-01-iad3.facebook.com
- 18.104.22.168 Reverse: edge-star-mini-shv-01-ort2.facebook.com
After that I thought it could depend on the DNS server location used by the visitor, but I tried my own (Deutsche Telekom, Germany), Google's (22.214.171.124) and a major one from France (Orange) and they all returned for
facebook.com the IP