Why a CDN is good for your site

Content Delivery Networks (CDNs) are great way to both improve the performance of your site and protect it against attack.

In a recent load test, comparing the effect of using a CDN at a level of load where the server begins to struggle without a CDN, we saw:

  1. Number of requests fell significantly
  2. Average response time per request went up
  3. Total number of journeys / donations completed went up

This might seem confusing, since reducing the response time and handling more requests is typically how one ensures one takes more donations.

A CDN will typically reduce the number of requests for static assets made to your site – and most solutions require more static assets than dynamic ones (e.g. a ‘dynamic’ page may contain several ‘static’ images).

As such, because static assets are generally served faster than dynamic ones, average response times should increase. In fact, the response time for those dynamic pages alone is likely to reduce, as the server is able to focus its efforts on these more expensive pages.

The total number of journeys and donations therefore increase, because overall the requests are faster and the server less strained. In the specific test we ran, the improvement was an ~40% increase in number of donation journeys that could be handled.

How they work

Instead of accessing your website directly, browsers instead go via the CDN, which in turn retrieves content from your what are then called your ‘origin’ servers.

Sometimes within the CDN platform there may be additional layers, with requests first going to a server geographically near the user’s browser, which then retrieves the content from a CDN server geographically near the origin server, and only then from the origin server.

To your website, the traffic all comes from the CDN, not from user’s browser directly.

Caching in the CDN

The key to how and why this might improve performance is simple: caching. When content is retrieved from your origin servers, some of that content (as per your rules) will be cached by the CDN.

This then means that subsequent requests for that content do not need to be made against your origin servers; but served directly from the CDN.

This immediately reduces the amount of load (CPU, memory, processor threads) on your origin servers and bandwidth on your server’s network.

CDNs versus Caching Proxies

Of course, you could also achieve this by putting a caching proxy within your own environment in front of your website.

This however still means that the traffic needs to flow across the internet all the way to your network. CDNs tend to operate by having local Points of Presence around the world – so any requests made are redirected to a CDN server geographically close to the user’s browser. These are generally referred to as Edge servers.

This means the corresponding latency and networking to the Edge Server is faster than it would be to your own network – and those Edge servers are in effect geographically load-balanced.

Furthermore, the Edge servers often do not talk to your origin Server directly; but instead to a server within the CDN network, geographically close to your origin server. This internal networking is normally optimised to be more efficient than the general public internet. Caching at this point also reduces load on your origin server, and ensures each Edge server does not individually add load to your server.

Security and DDOS Protection

CDNs also help improve the security of your website.

Whilst on the one hand they can hide the location your server – though if properly locked down, this should not matter – their real strength is in their ability to block a Denial of Service attack before it hits your servers. When their systems or engineers spot an issue, they can block such attacks at the CDN level – and because their systems are already distributed, they can effectively block a DDOS attack in a way no single device can.

CDNs and Serverless

Using a CDN with a serverless environment has an additional benefit: cost savings. Most serverless environments operate on a pay-per-use principle – so if a CDN reduces the use of that part of the solution by 50%, then corresponding costs will be reduced by 50%

Some CDNs also allow a certain amount of computation to be done within the CDN itself: be that Edge Side Includes (stitching together separate elements of the page into a single output) or Cloudflare’s Workers. This further reduces the load on your servers by migrating the load for relatively trivial processes from your origin servers to instead run distributed within the CDN’s cloud environment. Such services however are more costly and can couple a solution to the choice of CDN.

Sounds expensive…

It can be. Services such as those provided by the likes of Akamai can be costly to implement and have traditionally been used by large scale enterprises (for example, companies like Microsoft). The benefits for such large organisations tend to outweigh the costs.

However, companies like Cloudflare have offerings that provide almost all the benefits described above; at no cost. The downside with Cloudflare is that their system works by managing all the DNS records for your domain – which conflict with the way in which you currently manage your DNS records.