Content Delivery Network | System Design part - 7

 Content Delivery Network is a network that acts as a network for servers which are spread over a wide area across the countries, These servers cache static content like images, videos, CSS and JavaScript files, etc..,

Whenever a user opens a website, the CDN geographically closest to the user will deliver the static content, To convey it in simple terms we can say that, if there is a CDN in Hyderbad India that holds the static content of a website 1PerDay.com, people visiting that website from Mumbai takes less time to load the page compared to a person who is opening the website from Srilanka.

To make a better user experience by loading the content of the webpage quickly, companies who have more market from other countries prefer to store their static content in local CDN's 




Along with the static content, CDN also stores other things based on the developer's configurations, Such as frequently accessed images, videos, and posts.





  1. User A tries to access an image from the image URL, where the domain of the URL is provided
    by the CDN, Let's look at some sample image URLs provided by CDN 
    1. https://1peruser.cloudfront.net/image.jpg
    2. https://1peruser.akamia.net/iamge_storage/image.jpg
  2. CDN server checks in its cache and if it didn't find [Cache Miss], It will request the image from the original server.
  3. Generally, along with the file, It will also receive a few headers like TimeToLive TTL, Which lets the CDN know how long it should stay in the cache
  4. Once it receives the file, it caches the image and sends it back to User A
  5. User B sends the request to access the same image
  6. This time since the CDN has the file in its cache, it will directly send it back to the user instead of doing a server call.

Let's look at a few considerations before using CDN for our website 
  • Cost: CDNs are run by third-party providers, They will charge for every request they make to our web server, Hence it is advisable not to cache contents that are not frequently used
  • Appropriate cache expiry: Setting an appropriate cache expiry is very important. If the TTL or expiry of the content is not set properly there are chances of getting outdated data for long TTL and frequent web requests for short TTL
  • CDN Fallback: Webservers should design in such a way that if the CDN fails to respond, the requests should traverse to the original web servers.
  • Invalidating files: To replace the outdated content we can either use version control or we can use APIs provided by the CDN vendors

Comments

Popular posts from this blog

A complete guide to K-means clustering algorithm

What is Exploratory Data Analysis? | Part 1

COMPARABLE VS COMPARATOR