Content Delivery Networks, also known as a CDN, is a “self-storage” for your website. Not only can you store things in your CDN, but they also provide you with an extra layer of Security, Performance, and Reliability. A CDN is a service you pay for, such as Cloudflare or Akima. Any requests coming to your site would go through your CDN. If that request has not been cached at the CDN, it will come to your internal servers for processing. The server will return that request payload, such as a website page, back to the CDN, and it will then cache the page. This way, any new request coming to your site for that same page will get served from your CDN.
A CDN provides an extra layer of security because it protects you from a DDOS attack. So if you’re getting swamped with requests, your CDN can help hold them off. Alongside this, they process every request coming to your site to enforce specific rules and regulations, such as forcing all HTTP requests to be a HTTPS. They also help manage the proper certificate you need to allow your site to be secure, which is an extra headache you would have to do yourself if you host your servers without a CDN.
Say you have 1000 requests to your home page in a single day. Each request to the homepage will be the same response. Without a CDN, your internal servers will have to compute and render the homepage 1000 times, which can be a lot of work and costing you money. If you have a CDN, only the first request will come to your internal servers. That first request will then be cached at the CDN. The next 999 requests will get served from your CDN, saving your internal servers a lot of time and processing power. Serving the homepage from the CDN’s cache will speed up your site because it would be much quicker to serve the generated content than always having to regenerate it. Also, CDNs tend to compress the response payload, making them much smaller and quicker to download on the user’s browser. You can take the same approach with APIs. If you have APIs that return the same data, you can cache them in your CDN. You can also define cache keys to say each time a person requests information given a certain input, it will have its own cache. An example of this would be a product API. Each time someone requests pants from the API, cache and serves them the pants data. Suppose they request shoe from your API, cache and serve them the shoe data. The API is the same, but the cache key would be the product they are requesting. You can read our Web Dev post for more information on this flow.
Lastly, because a CDN caches the information on your site it can still serve your users if your site is down. Even though your site may be down for some time, your users won’t realize it because they can still see the page. Generally, CDN’s have many servers worldwide, which helps to speed up and keep your content download quick, no matter where your user is on the globe. For example, if you write a blog post and serve it to someone in Germany, it would get cached in some server in Germany if your CDN provider has them there. Other German users viewing your page would see it quicker, as they would not need to come to the USA for the page.