jcd.lol

anycast

Since I am using Gitlab and Cloudfare to deliver this site via a CDN, I got curious about how specifically CDNs work. My previous sites have largely been backed by a webserver I hacked together myself, and didn't even have a caching layer. They were the definition of unicast: a single user (usually me) pointing their browser at a URL and then the network architecture of the Internet pointing them to a single machine, which in my case was a shared host somewhere in Texas. When that box was down, the site was unavailable.

With CDNs, content is delivered via anycast. The network architecture doesn't resolve a URL to an IP that is backed by a single machine. Instead, routers maintain a list of potential servers that all advertise themselves as the address of a given IP. When a request for that IP comes in, the routers delegate it to the server that is "best", for some definition of best. Usually, best means having the lowest network latency to the client, but it may also take into account network load or do a simple round robin to several servers that are deemed close enough.

There's a lot to be gained in this approach (lower latency, resilience, redundancy, etc.), which of course makes intuitive sense. I didn't realize that routers could dynamically choose from a list of servers all advertising the same IP. It's hard to imagine it working any other way once you realize it tho.