What and Why of CDN

CDN

Content Delivery Network (CDN) in simple terms is a collection of servers spread across the globe. In other words, a CDN is a network of servers in which each request will go to the closest server.

Need For a CDN

For any web application, data can be categorized into either static or dynamic content. Dynamic content is the one that generally comes from a database. Static content is like CSS, images, JavaScript, flash files, video files and so on.

Now one may ask, how are requests served when a user enters an URL into the browser? Interesting, let's have a look at it. Before knowing a CDN and its usage, it is very important to understand this process.

How a Web Page is Served

When a client requests any URL, let's say www.google.com in the browser, there is a server configured to listen to any request that comes in for www.google.com. A server in turn performs some computations and sends raw HTML back to the client.

Raw HTML contains many links, like CSS, JavaScript and so on. Now for each and every link (CSS, JavaScript and so on), the client will make more requests to other servers, which means for each and every static resource, the client will make a request to the server. Now one can easily imagine the number of requests sent for a single web page. You can view this by using any of the debugging tools.

In case of a small website, all these requests are served from a single server. So, a single client is having many connections with the same server.

For a server to be serving millions and millions of requests, it may run out of resources. Can't we optimize something here?

client server

If you look at the figure shown above, the points marked in red are the intermediate nodes that serve free of cost and nodes at both ends fall into the paid category. We may have a very good bandwidth at the first and last node but those intermediate nodes hardly guarantee any performance or throughput. In essence, the further the user is from our infrastructure, the more he will notice these performance issues.

A CDN has been designed to solve all these shortcomings. There are many CDN providers available in the market today (in other words Akamai, Interwoven). One of the CDNs that I worked with is KeyCDN.

KeyCDN

KeyCDN has points of presence (POPs) all around the world. So, whenever a request for a webpage is submitted by a client, it will go to the closest server available. In this manner, your request doesn't need to go a long distance plus there won't be many requests between the actual server and the client. KeyCDN also provides various ways to control your settings including delivery status and reporting. It also has a very intuitive dashboard and the most impressive thing is, it is affordable!

A CDN will deliver all the static content. So, actual dynamic content is kept on the company's server and the static content is redirected to the CDN provider. So, there are multiple advantages of doing this.

Advantages of using CDN

  • Client request will go to the closest POP to get the static content rather than going all the way to the web server.

  • The actual web server will have more bandwidth available as the CDN takes a lot of the load.

  • Failover: If a server goes down, the CDN will automatically reroute the traffic to the next available server.

  • The biggest advantage is caching. Whenever a request comes in for the first time, the content will be cached on an edge server. When the next request comes in, it will read the data directly from its cache.

Enjoy learning!!!