CDN came into existence in the 1990s to diminish the performance bottleneck of the Internet. Now CDN is a crucial backbone of the modern internet to serve downloadable objects (media files, software, documents), applications (e-commerce, portals), live streaming media, on-demand streaming media, and social media sites.
Left: Distribution using single server Right: Distribution using CDN
How Does CDN Work
CDN is a collection of many caching servers in multiple geographical locations each(a.k.a., points of presence, or PoPs) connected together. Each PoP contains the cached version of the website. When a user requests a webpage the, CDN algorithm redirects the request to the server which is closest to the location of the requesting user(i.e, location with fewest hops), hence decreasing the latency and optimizing the performance.
CDN VS Load Balancer
Both CDN and Load Balancers are used to maximize the website/application uptime.
But a CDN is only good for serving static files only. Many sites cache static assets in CDNs because these files do not change often, and response times for serving those cached assets are quicker than requesting from the origin server.
For Serving anything dynamic we will prefer Load Balancer. Dynamic content such as server-side code, databases( which change frequently), will be benefited by having multiple servers behind a Load Balancer.
What are the benefits of using CDN
- Improved Website Load Time – By delivering the content from the nearby CDN server to the user (a.k.a POP), the user experience less page loading time.
- Reduced Bandwidth Requirement – CDN is able to reduce the bandwidth requirement of website hosting by reducing the amount of data, the original hosting server has to provide.
- Fault Tolerance – By distributing the data geographically among many servers, the CDN can handle more traffic and make the system fail-safe(i.e, even if one CDN server goes down, others will keep on functioning).
- Improved Website Security – CDN improve security by providing DDoS protection and web application firewall.