Content Delivery Networks: A Primer
Content Delivery Networks (CDNs) cache your content around the globe to reduce latency and improve performance for end users. It is a very powerful tool and can be leveraged by any web site. Historically, CDN providers have been very expensive and were not practical for most people. Now things have changed and there are many CDN providers that cater to cloud customers who want pay-as-you-go service.
How a CDN works
CDN providers place servers strategically around the globe so that content can be served quickly to all users. These are usually referred to as Edge Servers or Edge Locations. When a user makes an HTTP request, a domain name is resolved to one or more IP address(es) that belong to the CDN.
The key here is returning IP addresses that are close to the requesting user. There are various methods to determine the user's location and which Edge Servers to return:
- Use Anycast for the CDN's name servers to determine the closest Edge Location.
- GeoIP lookup of the requesting DNS server. This goes on the premise that a user's configured DNS servers are close to the user. This is typical when using your ISP's provided name servers.
- Use Anycast for the CDN IP addresses which means that packets should be routed to the closest receiver. (CacheFly, MaxCDN)
- Experimental - DNS requests carry the originating user's subnet -- this can be used to help determine a physical location. See draft-vandergaast-edns-client-subnet-00
By running the following command the name www.chrismoos.com will be resolved to CloudFront's network:
The record www.chrismoos.com is a CNAME that points to d38g1j01afvwut.cloudfront.net., which is provided by CloudFront and is a unique domain for my CloudFront distribution.
This CNAME is then resolved into multiple IP addresses.
Looking at the first A record with the IP 220.127.116.11 shows that it is a server in Los Angeles (lax) which is physically close to me (I am in Phoenix, Arizona).
Spoofing your location
Making a query to a DNS server in Germany for www.chrismoos.com gives different results:
The IP address 18.104.22.168 resolves to:
The above shows that the server is in Amsterdam, which is physically close to the DNS server we sent the request to (in Germany).
Serving content fast
Telling the user the closest server is only half the battle. Now these geographically distributed Edge Servers need to actually provide content -- and deliver it fast.
In the next part I will discuss the importance of HTTP caching when using a CDN and how to balance performance and freshness of your content.