What are CDNs?
CDNs are essentially globally distributed caches—data storage and delivery points closer to your site visitors. While your server may be in the USA, if a significant number of your users are in Australia then it makes sense for your content to be ready and waiting somewhere in the South Pacific region. This is achieved through the use of “edge servers,” which serve static content such as images, JavaScript files, and HTML to your users. Of course, if another user is in Buenos Aires, you should offer an edge server in South America, too. There’s no limit to how many edge servers you can have.
Benefits of distributed caches:
- Reduced load on the origin server, which only needs to be referred to for dynamically generated content.
- Massively improved performance, because the distance between your user and your content is reduced and the content is routed through fewer bottlenecks. This makes for a better user experience and higher conversion rate.
- Caching is taken care of for you if you use a commercial CDN provider. Say goodbye to Varnish configuration and maintenance headaches.
- CDN providers can protect against DDoS attacks.
One of the main challenges with using CDNs is ensuring that content isn’t out of date, while also avoiding routing requests to the origin server unnecessarily. Broadly, there are two approaches to this: pull and push. “Pulling,” the CDN can request any resource it doesn’t already have from the origin server, then store it for future reference and serve the cached resource in response to identical requests in the future. Or you can anticipate requests by actively “Pushing” your content to the server before that specific resource has been requested.
Broadly speaking, pulling is suited to situations where content changes regularly, pushing, where content is largely static.
A related challenge is “cache invalidation,” defining (or scheduling) when content in the distributed caches could be out-of-date and signalling for a refresh or update. This ensures resources available on the CDN server are in sync with the origin server.
If you choose a commercial, software-as-a-service CDN, then all of this should be taken care of—depending on the level of configurability your provider offers.