Imagine a world where every web page loaded instantly, with not a single millisecond of wait time. Although this isn’t possible yet, technologies are emerging that are helping us to get a few steps closer.
A content delivery network, (or CDN for short), is one of the steps towards achieving this goal.
In this article, I’ll explain what a CDN is, how a CDN model compares to the traditional web hosting model, discuss the pros and cons of using a CDN for your website, and then lastly, show you how to get your website started with a CDN.
What is a CDN?
A CDN is a system of web servers, geographically dispersed across the world, each of which hosts a copy of your website, in order to improve the way your content is delivered to your users.
What is the primary purpose of a CDN?
The main purpose of a CDN is to serve your website’s content more efficiently (ie faster), to end users.
If you use a CDN, when a user loads your website’s content, the CDN server that’s closest to the user will provide that content.
Because the content has less distance to travel, it get’s to the user quicker, which means your website loading times are faster!
As we’ll see though, that’s not the only advantage of using a CDN!
How does a CDN work?
As we’ve already discussed, when you use a CDN as part of your web hosting setup, each of the servers in the network hosts a copy of your website.
These CDN severs are called “edge” servers because they are on the edge of the network and closest to the users.
This is in contrast to the “origin” server, which is provided by your web hosting company and is where your files are automatically uploaded and stored, when you are creating and updating your website.
You may be wondering how your website gets from the origin server and onto these edge servers?
Well, that depends on whether yours is a push or a pull CDN…
What is Pull CDN (and how does it work)?
A pull CDN setup works by pulling files from the origin server, as and when they are needed.
The first time that a user requests a file, the edge server will need to read the file from your origin server (i.e. your current hosting provider).
The edge server will then store a cached version of that file. A “cached” version just means a copy of the file from that paticular moment in time.
Future requests for the file will come directly from the edge server (rather than being pulled from the origin server), until the file expires (becomes out of date).
After expiration, the file will once again need to be refreshed from the origin server and cached.
What is a Push CDN (and how does it work)?
A push CDN allows users to upload (“push”) their files to the CDN itself, and the files are then immediately distributed to the edge servers, once uploaded.
So your files are already stored on every edge server, without needing to be pulled from an origin server.
This is a less common option; however, it is advantageous for distributing large media files, since a copy of the media will always be stored on the edge servers.
Does a CDN replace your web hosting?
No, a CDN does not replace your web hosting. They work in conjunction.
Your original files are all stored on your web host’s server. This is the origin server.
The CDN servers only contain copies of the files on the origin server.
If you get rid of your web hosting, the CDN won’t have anywhere to copy the files from!
Video Summary of a CDN
If you’re still bit confused, here’s a quick video that explains a CDN in very simple terms:
The problem with web hosting without a CDN
With the traditional web hosting model, all of your website’s files (HTML, CSS, images, etc.) are hosted in one location in the world – basically wherever your web hosting provider’s datacenter is located.
When end users access your website, the site’s content is always retrieved from this one location.
There are several disadvantages to this:
1. Speeds decrease over distance
If your web hosting provider’s datacenter is located in Texas, every time a user wants to load your website, the content will be delivered from that Texas datacenter.
Transfer speeds tend to decrease the further the user is located geographically from your server, since the files need to travel a further distance. The further a user is located from the datacenter, the longer it takes for your website to load.
So, a website user in the UK, will load your website slower than a user in the US, due to their proximity to the Texas datacenter.
2. Limited transfer rates
Consider a situation where multiple users are all trying to load your website at the same time.
Just as your personal computer has limitations on how fast files can be transferred across the network (throughput rate), servers also have limitations on how fast they can transfer files.
Is your current web hosting prepared for such a spike in traffic?
Specifically consider shared hosting solutions, where transfer rates are not specified. In these and other environments, transfer rates may be quite limited, which can result in a noticeable performance impact when there is a surge in traffic to your website.
For these reasons, a surge in traffic may increase your website’s loading times, as the website’s content is sent to all of the end users at once.
The advantages of using a CDN
With a CDN model, we can overcome the disadvantages of the traditional web hosting model. Indeed, a CDN has several advantages, such as:
1. Faster load times (by serving content from the closest server to the user)
Remember that the further the user is located from your hosting provider’s datacenter, the longer it will take for your website to load, since files need to transfer across a further distance.
A CDN will serve content from an edge server that is either closest to, or most efficient for, each individual end user, based on where they are located in the world.
For example, if someone in China were to load your website, the CDN might automatically load a copy of your website’s content from a server in China. If someone were to access your site from the UK, a server in the UK might be used instead to load your website to that specific user.
The CDN will automatically determine which server is the most efficient choice for each end user.
2. Better traffic spike handling (by dispersed transfer of files)
As mentioned previously, servers contain restrictions on how much data can be transferred through them at once. A CDN helps to improve your website’s performance when multiple users are trying to access it at once.
Given the nature of how CDN works, simultaneous requests to your website will likely be handled by multiple servers in multiple areas across the world, depending on where the requests come from.
In this way, one particular server is not flooded with all of the requests from users. CDN providers will also implement other procedures in order to ensure that your files will load efficiently even amidst a spike in traffic.
3. Better security (thriough DDoS mitigation and protection)
A DDoS attack is when your server is flooded with illegitimate requests for your website, with the purpose of crashing your site or to cause increased bandwidth charges due to excessive transfer.
Your CDN provider will likely offer DDoS detection and mitigation mechanisms, which will help to improve your website’s performance and uptime amidst a DDoS attack.
The disadvantages of using a CDN
There are however, a couple of disadvantage of using a CDN.
1. Cost: CDNs are typically pay-per-use
CDN providers often charge based on how much content you are transferring. Because of this, your monthly cost varies by the month.
Your current web hosting provider may already include a certain amount of monthly transfer as a part of your current hosting package; therefore, you will need to consider whether the added cost of CDN is viable to your business’s online presence.
Note that “push CDN” providers often also charge for storage space (see below).
To help you understand what it will cost you to transition over to the cloud, consider the following scenario…
Say your website size is 1MB in size and your CDN provider charges $0.085/GB of transfer. The cost of 10,000 users accessing your entire website would be: ((1/1024)×10,000) ÷ 0.085 = 114 cents, or $1.14 per 10,000 requests.
As you can see, this is not an outrageous cost.
However, many CDN offerings read your files from their storage location with your current hosting provider, which is an additional cost. This origin server could be a file storage system such as Amazon S3, or it could be your current hosting provider.
If your website contains dynamic content, you will still need to maintain a hosting solution that can process those types of files.
Since CDN solutions are often pay-per-use, a DDoS attack might be financially unfavourable – the drastic increase in file transfers caused by this type of attack would result in an increased cost for your business.
However, CDN providers are working on detecting and mitigating these types of attacks, as discussed earlier.
Note: many of the best web hosting providers now include free CDN services in their plans.
2. Extra configuration needed to cache changing content
Keep in mind that a CDN works by caching copies of your website’s content across the world.
However, most websites include some content that changes depending on the specific user accessing the website or other criteria (welcome messages for a specific user, shopping carts, etc.).
This type of content is not as trivial to cache across the world, since it is constantly updating per-request.
Streaming files are another form of content that require special attention to be used in the CDN. See below for some more details.
Other CDN Considerations
Refreshing the file cache when updating your files
When you need to update one of your files using a pull CDN, all of the cached copies across the world will need to be expired too so that they are refreshed on the next request.
In order for this to happen, you may need to either wait for the default expiry time (which varies by provider), or force the cached files to be invalidated immediately (by clearing the cache manually).
Although updating your files may involve this additional step, your website’s static files will likely not be updated too often.
Ensure sufficient expiry time for infrequently accessed files
Pull CDN solutions do not necessarily contain a copy of your files on every edge server at all times (discussed in more detail below). If there isn’t a cached version of a file already, the file must be pulled from the origin server.
This is more of an issue for larger files such as videos, since the performance impact of loading these types of files from the origin server might be felt quite significantly.
Some solutions to this issue are to increase the expiration time of the cached file (if possible), so that the file does not need to be refreshed from the origin server as frequently, or to store large files on a push CDN solution (see below).
Static vs. Dynamic Content
Websites contain two primary types of data – static content and dynamic content.
For example, your company’s logo won’t change in appearance, no matter who visits your website or how many times you reload the page.
Dynamic content changes depending on who requests the data or other criteria.
For example, when John logs into his bank account, he sees his balances. However, when David logs in, the balances are not the same as what Joe sees.
As another example: after logging into the WordPress dashboard, you will see a message such as “Howdy, John!”.
Content that changes depending on the user or other criteria is considered dynamic content.
How does a CDN handle Static, Dynamic, and Streaming content?
At this point, we come to an important question: “What kind of files can I store on the CDN?”.
Since static files tend to stay the same at all times no matter who is loading your website, they are well suited to be cached across the world via a CDN, since the files are updated infrequently.
As far as dynamic content (i.e. a shopping cart), there usually isn’t one single file that can be cached across the world, since it often changes for each user or other criteria.
However, CDN providers are implementing solutions to improve the efficiency of loading dynamic content, such as finding the fastest route between the user and your hosting server.
Many CDN providers have also implemented solutions to stream both live and on-demand media via a CDN.
How to set up a CDN
So now, you’re probably thinking, “I’m convinced that my website needs a CDN! How do I transition?”.
The answer depends on which hosting provider you use and which type of CDN solution you want.
Some web hosting providers provide an option to easily enable CDN via their control panel. Other setups require some extra steps.
Add a CDN layer to your entire website
This option is one of the simplest to set up for small business owners. Every request from users to access your website’s content will first be filtered through a system managed by a CDN provider.
Static content will be loaded from the CDN, whereas dynamic content will be loaded directly from your existing server (or a technique might be used to improve the loading time of dynamic content, as discussed earlier).
A pull CDN will actually be implemented behind-the-scenes in order to distribute files via the CDN.
CloudFlare is one such company that offers this type of CDN solution. Some companies such as CloudFlare will also provide other enhancements for your website’s performance beyond CDN alone.
How to set it up
The main step in setting up this type of CDN system is to update your website’s DNS records to point to the CDN layer. The CDN layer will then route requests to your origin server as necessary.
You will still need to keep your current hosting solution in order for the CDN to pull files from it.
How to set up a Pull CDN
You specify the location of your files on your origin server to distribute on the CDN. The CDN will then pull the files from the origin server as necessary.
You will also need to either update the links to the files in your website to the CDN’s endpoint, or update your DNS settings to point to the CDN.
How to set up a Push CDN
Upload your files to the CDN provider. You will also need to either update the links to the files in your website to the CDN’s endpoint, or update your DNS settings to point to the CDN.
Should I leave my web hosting provider?
No. Even after purchasing a CDN solution, you will need to stay with a web hosting provider.
Keep in mind that a CDN is used to cache content; if your website contains any dynamic content, you will still need to keep your current hosting solution in order to process that content.
Which hosting companies provide a CDN?
Many hosting companies provide a CDN as part of their shared hosting plans these days:
- SiteGround (use their own bespoke SiteGround CDN)
- Bluehost (Cloudflare is pre enabled)
- Kinsta (a paid Cloudflare plan is included for free)
- WP Engine (a paid Cloudflare plan is included for free)
- HostGator (Cloudflare is included on Business plan only)
- IONOS (Cloudflare is included on the Expert plan only)
- Cloudways (Cloudflare Enterprise can be added for just $4.99 a month)
CDNs are a viable solution to improve the efficiency of your website by reducing the time required to transfer files to users. This serves to likely increase customer retention on your website, and possibly even improve your search result rankings.
CDNs will also reduce the load of file requests on your current hosting setup, which may help in handling large traffic volumes.
However, a CDN often comes at an increased cost. Your website deserves the performance improvement that a CDN could offer, but the benefits must outweigh the potential costs and other tradeoffs.
Don’t forget that a CDN is only one of many steps you can make to improve the performance of your website. Choosing a fast web host is the first (and most important).
And there are also many other things you can do to generally increase the speed of your website (such as image compression), and specifically improve the loading times of your WordPress website!
Have you used a CDN for your website? Let us know in the comments below what you think about CDNs!
THE BEHIND THE SCENES OF THIS BLOG
This article has been written and researched following a precise methodology.Our methodology