Does a CDN still work even when my server is down?

Solution 1:

It would depend on who is hosting your CDN. If you host your website on one server, and the CDN with a 3rd party then it is likely that your CDN will remain active when your website it down. This may not be the case however, as some CDNs only distribute content they can verify is on your website.

A side note, CDNs are not for hosting your whole website. So if you're thinking that you can use one to replace your web hosting or use it as some sort of failover plan, you're barking up the wrong tree.

TL;DR - You'll have to ask your CDN provider.

Solution 2:

CDN's are designed for scalability and performance, but not for high availability. At any given time, they may require access to the original files.

Most people use them to store static files such as images, css and javascript files. Some can be configured to cache HTML, but that's only if you have a completely static website. If that were the case, you could host the whole thing on S3 and wouldn't need a server at all.

Solution 3:

Generally, yes, up to the TTL.

When using CDNs you usually configure TTLs (time to live) for your content. This is a maximum on how old the cache can get before it decides it absolutely has to refresh the cache with the newest content. For example, suppose you configure all *.jpg URLs to have a 5 minute TTL.

Then if your server goes down, you have an extra 5 minutes to bring it back up before users will notice. Well, at least for .jpgs. Well, at least for .jpgs that happened to have gotten cached beforehand.

Also, some CDNs use features like Akamai NetStorage where you can upload content directly to the CDN -- the CDN is given some content and told to serve it directly a priori. Since there's never an "on-demand" "pull" style caching going on here to begin with, that should of course work when your server is down.

As the other posters noted though, this isn't what CDNs are designed for and they provide NO guarantees that this behavior will work. It just happens to usually work (and it's awesome when you watch it happen!). And of course for specific technical details you'd have to contact your provider.