Content Delivery Networks and You
Published: 2021-03-14 20:04:15

Imagine for a moment that you are your favorite piece of media. You might be a song, a tv show or even Irving Kershner's 1980 all time classic, *Star Wars Episode V: The Empire Strikes Back*. As a popular piece of media existing in the golden age of streaming, you most likely exist on a server somewhere in the midwest United States (Don't @ me, Disney. I don't actually know where you keep your secrets).

So, what happens when someone wants to watch you in Tokyo, Japan? Do you travel the roughly 5,000 miles through the Pacific via [seafloor cables](https://www.nytimes.com/interactive/2019/03/10/technology/internet-cables-oceans.html), accumulating increasing amounts of latency along the way? In today's day and age, most likely not. Instead, your content provider probably has implemented a CDN to get you there a lot faster. 

CDN is short for [Content Delivery Network](https://www.cloudflare.com/learning/cdn/what-is-a-cdn/). It's a term used to refer to a global system of redundant servers designed with the purpose of cutting down on the latency between a domestic host and a client on the other side of the world by utilizing a unique form of [caching](https://aws.amazon.com/caching/cdn/). 

Notice that I used the term *redundant*, which might set off more than a few negative alarm bells in your primal, efficiency obsessed programmer brain. But in this use case, redundancy is actually the primary advantage. It ensures that if one point of the network goes down, there is immediately another [edge server](https://www.cloudflare.com/learning/cdn/glossary/edge-server/) to take its place.  

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/obssaz09b3fwgbtlbp0p.png)

By increasing redundancy, we are also decreasing the maximum possible load on the original server by avoiding network [bottlenecks](https://en.wikipedia.org/wiki/Bottleneck_(software)) before they even happen. This will also present an obvious security benefit when configured correctly, as attackers from across the world would only have immediate access to their nearest edge server, and not the root server. 

Another big advantage here is *speed*.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n9roc16w99hv1fvfi5x.png)
 
 
Content will load significantly faster if it's coming from a CDN within your own country, opposed to being laboriously beamed from halfway across the world. This makes a huge difference in combatting streaming [latency](https://www.haivision.com/resources/streaming-video-definitions/video-latency/) and will always result in more responsive media, whether it's audio, video, or even just loading elements into a simple [html site](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Author_fast-loading_HTML_pages). 

So how might you, the budding software dev, utilize a service like this? Well, it's actually a lot simpler than you might think. 

For the sake of providing a [practical example](https://www.youtube.com/watch?v=NV2eKYmQF6Q), I'll walk you through some of the basic steps of setting up your site with [cloudflare](https://www.cloudflare.com/), a CDN service with a pretty robust free option. First, you'll want to sign up for an account, then add your site when prompted. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zu4bekkvdkpc4si4tu98.png)

Then, it'll take you through a series of steps including choosing your membership level, giving you a list of associated [DNS records](https://www.bluehost.com/help/article/dns-records-explained), then prompting you to link your account from wherever you [registered your domain](https://www.pcmag.com/news/how-to-register-a-domain-name-for-your-website). It may take a day or so for this step to complete, so just be patient. 

Finally, you'll want to dynamically link cloudflare to your site in the [src script tag](https://www.w3schools.com/tags/att_src.asp) of your HTML file, which will probably end up looking something like this:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrhpx9n7z3j0thz1qjwi.png)
 

And voila! Your site will now be more secure, faster and more accessible to the world at large, all at no or little cost to you. 

Before we part ways, [here](https://www.youtube.com/watch?v=Bsq5cKkS33I) are a [few](https://www.youtube.com/watch?v=pViIP0IF-nY) [videos](https://www.youtube.com/watch?v=YXQpgAAeLM4) that may help you [understand](https://www.youtube.com/watch?v=CiphZWq3ST4) CDN's in a broader context, as it is hard to explain everything in one short blog post. Simply put, CDN's are fast, secure and increasingly needed in modern web design.