beautiful street time lapse traffic blue sky dark background

How Does CloudFlare Serve Websites Compare to a Regular CDN?

Does a CDN Keep Serving a Website When the Hosting is Down?

First an answer to your question. Typically a CDN doesn’t really do what you are looking to do. A full site caching service like cloudflare does

Then What is the Purpose of a CDN?

CDNs – Content Delivery Networks are really for serving your static items (images, video, JS, CSS, pdfs, etc. etc).

The reason people use CDNs is so that you can serve all of those big things from a location as close to your visitor as possible. Because static items are generally larger files, A CDN can speed up the user experience for your visitors. Its a lot faster to download something from your city rather than from across the country. A CDN also has the additional benefit of offloading the responsibility of serving those things from your main web server which means it can then do the things it has to a bit faster as well.

How does a CDN Work?

How a CDN generally works is by using a different URL for your static things than your real website (say images.mysite.com instead of www.mysite.com). The subdomain in the URL would be a pointer (cname) to a CDN url. Once a request was made for one of your images the CDN would try and figure out where that request was coming from and serve the image from a location closest to the visitor.

So in a simple example – A visitor requests your website by typing www.yoursite.com. into their browser. Your homepage has a bunch of nice big images and when you added them, you used the URL Images.yoursite.com in the Href. When you signed up for the CDN service they gave you a CDN URL like Customer.CDNDomain.com and you configured your DNS server so that images.yoursite.com is a CNAME to Customer.CDNDomain.com.

Once the visitor gets your HTML from your webserver, it starts trying to also download all of the images and other things referenced. So your browser would lookup images.yourdomain.com via DNS and the DNS server would say – images.yoursite.com is really customer.CDNDomain.com. So your browser would then try and lookup customer.CDNDomain.com to try and make a request, but DNS looks at the IP address you are coming from and tries to figure out where it is in a big database of IP locations, once it has some idea, it tells your browser customer.CDNdomain.com is really closetoyou.customer.cdndomain.com.

Your browser can then lookup that domain in DNS which will give it an IP that is really close to it. Now that your browser has the IP it can make a request for the actual image from somewhere that will deliver it very fast.

How Does Cloudflare Compare to a CDN?

Cloudflare is really a proxy/whole site cache. Visitors request your site from them and then request the site from you, cache it, and then deliver it back to the visitor. This can help with a lot of things, namely protecting your site from attacks or large spikes in traffic, but it can also pose problems if you have a lot of changing content on your site or interactive things like user logins, shopping carts, etc.

How Does Cloudflare Serve Clients My Website Comparing to a Regular CDN?

When you load a page the page source code looks like this:

Assuming your website is website.com the visitor will attempt to load the css, js and image from your server. With a traditional CDN you will need to upload the files to the CDN and then modify the URLs to use the CDN. This may vary between providers and they may have their own way to handle uploading files and such but the short version is the CDN hosts those files and you need to change your links.

Cloudflare is billed as a CDN but it’s more of a reverse proxy. Using the example before the request looks like this:

  1. User requests website
  2. Your server responds back with source code
  3. Users browser reads the code
  4. Users browser requests the website / files from the URLs given
  5. Users browser renders the output

Cloudflare however does this:

  1. User requests website
  2. Request goes to Cloudflare.
    2.1.1 If the page is not cached, Cloudflare requests the website from your server
    2.1.2 Response is sent to Cloudflare
    2.1.3 Cloudflare caches that response
    2.1.4 Cloudflare sends the code back to user
    2.1.5 User requests the files from the URLS given
    2.1.6 If they are on your domain, repeat this 2.1 branch. Cloudflare caches as much as it can
    2.2.1 If the page is cached, retrieve from Cloudflare

The difference is that every request to your site goes through Cloudflare and Cloudflare tries to transparently cache it. CDNs you are given a specific URL.

Links

Related Reading: Information on Making an Authority Website, from SEO, Social media, and to WordPress Mastery

Source:

  • Does a CDN keep serving a website when the hosting is down? – [Reddit]

The Revisionist

I own this blog

What's Your Opinion?