Architecting Scalable and Fast Asset Delivery System | web server vs cdn

Whenever you create a website, you will face the dilemma of how to distribute the content (images, js, css etc) to the end user. Should you use the web-server itself, or use a content delivery network. Delivering content traditionally i.e. from the web-server would deliver all the content from the web-server even if user is across the globe which is a hit on your website load time.

Over a past few years, content delivery networks like cloudfare, cloudfront etc have become very popular particularly because of speed, reliability and drop in prices. Delivering 1 gb of content via cloud front costs only 0.085$. Powerful edge servers are located across various locations all over the world which forms the crux of why serving through cdn make your website fast.

While there are pros and cons of using CDN or web-server, the pros of CDN by far outweigh its cons.

Performance: Reducing Network Latency

Various powerful edge location servers are present all over the world and your content will be served from these locations directly to the user. The closest edge server will be chosen to deliver content which reduces the network latency thereby improving the content delivery time which eventually improves the website load time.

Reduction of load on web-server

The load on your web server gets reduced as the content delivery network takes majority of the load. This ensures that your website will work properly even with a small sized server; thereby reducing the server cost. This reduced load on your web-server also ensures that you can serve more concurrent requests without any need to upgrade it.

Reliability: Redundancy Removal across edge servers

When your website traffic starts increasing, you will need to use load balancers to effectively manage your traffic. However if you are serving static files from your server only, you will have to ensure that the static assets are successfully replicated across all your web-servers. However using CDN with single origin server (amazon S3 or similar) removes this redundancy. This setup ensures that your content is present only at single place i.e. your origin server and distributed to the edge locations from there.

Scalability and SEO Benefits

Most content delivery networks will automatically scale based on the traffic and you don’t have to worry about scaling up your servers if you are expecting spikes in traffic. This ensures smooth experience for your users and removes additional setup overhead for you. Also a site’s load time is one of the key factors in Search Engine Optimization and impacts its search ranking. So using a content delivery network also improves your SEO score.

Having said that, you need to understand that CDN’s aren’t absolutely necessary, rather its a way of improving your website performance. You can still provide a decently fast website without a CDN but it will definitely be faster when using a CDN.

Using CDN is one way to improve speed, there are several other ways to further improve the page speed like setting expires header, minification, gzipping your content etc. Some of these are explained here

Let me know if you have any suggestions/feedback in the comments section below.

Fun FactGame of thrones season 6 is back, and its episode 4 is also titled as the book of stranger 🙂

Come on, I know you want to say it