You have probably already heard that CDN (Content Delivery Network) speeds up your statics delivery due to a distributed system of caches. But how does this work? In this issue, we try to navigate through this topic.
The main idea behind CDN is that to make our system more reliable and performant for distributed loading, we introduce a distributed proxy & cache that hides the original application. In doing that, we add a DNS record that points to the IP addresses of CDN. Under the hood, a CDN proxy node requests to our origin server and caches results. If an origin server outage is in place, our static data might still work due to edge-caching. So the next question how to find the best CDN edge node?
Round-robin DNS
Thanks to round-robin DNS and redundancy, we distribute loading between IP adresses of CDN (not necessarily evenly), but those IP addresses are the same for every region. Does not seem distributed? That is because round-robin DNS does not care about geographical distance. Anycast comes to our aid here.
Anycast
Anycast DNS is a traffic routing algorithm that allows to assign one IP address to many nodes. The approach has helpful advantages:
high availability thanks to multiple nodes with redundancy sharing the same IP address
lower latency because traffic is routed to the geographically nearest server
scaling via adding of new nodes
As an alternative for finding the closest destination for a request, it is worth mentioning GeoDNS, but it is out of the scope of today's issue.
This is still unclear how does this guarantee we do not go across the world to find the closest node? IXP will help us to answer how to avoid The Trombone Effect (inefficient network path of queries).
IXP
Internet Exchange Point (IXP) is a physical location. Internet Service Providers and CDN providers share infrastructure there to establish the most efficient cross-network communication. IXP is presented as one or more physical buildings and depending on a particular demand it is helpful to connect networks either for free or some members might charge for their service. So, clients ISP has its edge node in the closest to a particular client IXP which is well-connected with other networks and especially with CDN providers. A map of IXP can be found right there.
Batumi meetup
One week ago, I had a chance to speak at IT Meetup Batumi about “Practical Evolution of a Distributed System”. Watch the recording on their channel (click on the picture)