Back to all articles
DNSCDNAnycastNetwork Architecture

DNS and CDNs: How the Internet Delivers Content at the Speed of Light

Jamie LinJuly 15, 2024

We've discussed before that the internet is constrained by the physical laws of the universe. Specifically, the speed of light.

If you live in London, and you want to download a high-definition video from a server physically located in Sydney, Australia, that data has to travel roughly 10,000 miles through fiber optic cables. Even at the speed of light in glass, that journey takes time. It introduces latency. And if millions of people around the world are all trying to pull video from that exact same server in Sydney, the server will melt under the strain.

To solve this problem of geography and scale, the tech industry invented the CDN (Content Delivery Network).

Companies like Cloudflare, Akamai, and Fastly operate thousands of massive server farms strategically placed in almost every major city and ISP data center on earth. These are Edge Servers.

When a website (like Netflix or a major news site) uses a CDN, they don't serve their heavy images and videos from their own central servers. Instead, they upload a master copy to the CDN. The CDN then automatically clones and caches that data across their thousands of edge servers worldwide.

So, when a user in London requests a video, they don't fetch it from Sydney. They fetch it from a CDN edge server located just a few blocks away in London. The latency drops from 200 milliseconds to 5 milliseconds. The video starts instantly.

But this raises a massive technical question: How does your computer know to talk to the London server instead of the Sydney server?

The answer lies in a brilliant, slightly hacky manipulation of DNS (Domain Name System).

The Traditional DNS Lookup

Normally, DNS is just a phonebook. You type `example.com`, your computer asks a DNS server for the IP address, and the DNS server returns a static IP, like `192.0.2.1`. No matter who asks in the world, they get the exact same IP address.

But CDNs don't have one static IP address. They have thousands.

Geo-Aware DNS: The CDN Trick

When a website is fronted by a CDN, they hand control of their domain's DNS over to the CDN provider.

Now, when you type `video.example.com`, your computer's DNS request eventually reaches the authoritative DNS servers operated by the CDN.

This CDN DNS server doesn't just blindly read from a static text file. It runs intelligent, real-time code. It looks at the incoming DNS request and says, "Wait, who is asking?"

It examines the IP address of the user making the request. It checks that IP against a massive global geographic database.

  • "Ah, the user asking for this IP address is located in London on the BT network."
  • The DNS server then checks its own internal telemetry.

  • "Do we have an edge server in London?" Yes.
  • "Is that London server currently online and healthy?" Yes.
  • "Is it overloaded?" No.
  • The DNS server then generates a dynamic, customized response just for you. It replies: *"The IP address for video.example.com is 198.51.100.45"* (which happens to be the exact IP address of the London edge server).

    Meanwhile, a user in Tokyo makes the exact same DNS request for `video.example.com`. The CDN DNS server sees they are in Japan, and replies with a completely different IP address pointing to the Tokyo edge server.

    Anycast: The Network Layer Alternative

    Geo-DNS is incredibly popular, but it's not the only way CDNs route traffic. Some modern CDNs (notably Cloudflare) rely heavily on a routing trick called Anycast.

    In a normal network, an IP address is "Unicast"—meaning it exists in exactly one place in the world.

    With Anycast, a CDN assigns the exact same IP address (e.g., `1.1.1.1`) to hundreds of different servers around the world simultaneously.

    Wait, doesn't that break the internet? How does the network know where to send the packet if 100 different servers claim to have the same IP address?

    It relies on BGP (Border Gateway Protocol), the routing protocol of the internet. When the CDN plugs all those servers into the internet, they all announce to the global routers: *"I am the path to 1.1.1.1!"*

    When your computer in London sends a packet destined for `1.1.1.1`, the internet routers look at their routing tables. They see multiple paths to that IP. By design, BGP routers always prefer the shortest, most efficient path. The router automatically sends your packet to the London server, completely ignoring the Sydney server that claims to have the same IP, simply because London is closer.

    If the London server loses power and goes offline, its BGP announcement disappears. The routers instantly recalculate, find the next closest path (maybe Paris), and reroute your traffic there without you ever noticing.

    The Invisible Backbone

    Without CDNs, the modern internet—with its 4K video streams, instant software downloads, and dynamic web applications—would be impossibly slow and fragile. By combining the geographic cloning of data with intelligent DNS and Anycast routing, CDNs bend the rules of latency, making the global internet feel like a local area network.