An introduction to CDNs[Systems Design Sundays]
You want to make sure you understand CDNs for your applications
Hello hello my lovely reader,
In this post, we will cover the idea behind content delivery networks (CDNs). Almost every big website these days relies on these to help you have the smoothest viewing experience possible. This includes the FAANG companies, so learn this idea very well.
The highlights
The post will go over the following ideas-
What are CDNs- Instead of having one server sending information to every user, regardless of user location, we use a distributed system of servers to ensure that users connect with the server closest to them.
Why CDNs- Lower costs, protection against DDOS, better uptime, good for load balancing, and better experience for users.
Some cons CDNs- 3rd parties integrations can be problematic, extra costs, and CDNs need to be placed in an ideal manner.
Sound exciting? Let’s get into it.
What are CDNs
CDNs are a relatively intuitive concept. Let’s work through this with an example.
Some of you are followers of my YouTube channel. Looking at my audience demographics, it’s interesting how many places my viewers come from (I’m surprisingly popular in Africa and East Asia). If all viewers were accessing videos from the same server, the performance would be variable.
YouTube is still relatively low stakes. What about applications where latency is a huge factor? In such cases, users will suffer worse experience just by being far away. CDNs were made to address this pain point.
A CDN is simply a geographically distributed group of servers which work together to provide fast delivery of Internet content.By placing these servers strategically, users will be able to interact with data centers close to them, severely dropping the latency.
CDNs also implement caching to make this process much better. In Fasly writeup on CDNs, they had this to say,
A CDN helps you lower latency by temporarily storing copies of your content in cache locations close to your user. CDN services have caches all over the globe, so when a user requests your content, the CDN can intelligently deliver the content from a cache located close to the user. This reduces the time to deliver content, thereby making your website load much faster.
This comes with several other benefits. Let’s understand them now.
Why use CDNs
We kinda answered this already, but why specifically CDNs. YouTube could just buy their own servers and place them around the world, instead of paying someone for their CDNs. That way they get access to the server full time. So what is the reason that every FAANG company uses CDNs.
CDNs come with several benefits. They include-
Speed- The most well known benefit. Through the use of caching and optimizing, CDNs ensure that the most important parts of your website/service are delivered quickly. This performance is especially improved by combining with browser caching
Costs- When you use a CDN, you can still serve requests for content even if your origin servers are unavailable. This is because CDNs can serve cached content even if your service is interrupted. This process can lower the costs charged by hosting providers charge to move content out of storage. Add to this the savings that CDNs give you by allowing you to provision fewer servers, and the cost reduction aspect of CDNs is very strong.
Scaling- CDNs allow you to scale up your ops very quickly and in proportion to your needs. Instead of having a fixed number of servers that might be unused in downturns and runs out with spikes, CDNs scale with your needs.
Improved Uptime- CDNs distribute your content across a wider number of sources. This allows ensures that your content is atleast partially available, even during outrages, traffic spikes and DDoS.
Better Security- User often interact with the CDNs instead of the origin server. This acts as an additional layer of security.
Sounds like a magical solution doesn’t it? Unfortunately they do come up with some drawbacks that are important to consider.
Cons of CDNs
As good as they are, these are the following cons of CDNs-
If your service isn’t consistently high traffic, then CDNs can be a very expensive option. Also, keep in mind that when your traffic is locally clustered, CDNs won’t help you much.
Since CDNs are run by third parties, there is an incentive for them to use the data stored for targeted ads. This adds additional possible concerns.
Third Party—> Worse Support. If an issue comes up with the third party servers, then resolving them can slower and more painful. Consider your provider carefully.
If the centers are located poorly, then the users don’t benefit from the CDNs.
Compared to the pros, the cons of implementing CDNs for large scale, globally oriented systems are not as strong. That is why they have become such a prominent resource. Next time you are asked to implement Twitter/Instagram/YouTube/Netflix or any such service, make sure you remember to integrate CDNs into your solution.
If you have enjoyed this post so far, please make sure you like it (the little heart button in the email/post). I also have a special request for you.
***Special Request***
This newsletter has received a lot of love. If you haven’t already, I would really appreciate it if you could take 5 seconds to let Substack know that they should feature this publication on their pages. This will allow more people to see the newsletter.
There is a simple form in Substack that you can fill up for it. Here it is. Thank you.
https://docs.google.com/forms/d/e/1FAIpQLScs-yyToUvWUXIUuIfxz17dmZfzpNp5g7Gw7JUgzbFEhSxsvw/viewform
To get your Substack URL, follow the following steps-
Open - https://substack.com/
If you haven’t already, log in with your email.
In the top right corner, you will see your icon. Click on it. You will see the drop-down. Click on your name/profile. That will show you the link.
You will be redirected to your URL. Please put that in to the survey. Appreciate your help.
In the comments below, share what topic you want to focus on next. I’d be interested in learning and will cover them. To learn more about the newsletter, check our detailed About Page + FAQs
If you liked this post, make sure you fill out this survey. It’s anonymous and will take 2 minutes of your time. It will help me understand you better, allowing for better content.
https://forms.gle/XfTXSjnC8W2wR9qT9
Happy Prep. I’ll see you at your dream job.
Go kill all you Sleek Systems Designer,
Devansh <3
To make sure you get the most out of System Design Sundays, make sure you’re checking in the rest of the days as well. Leverage all the techniques I have discovered through my successful tutoring to easily succeed in your interviews and save your time and energy by joining the premium subscribers down below. Get a discount (for a whole year) using the button below
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75