What You Need to Know About Amazon's CDN
Content Delivery Networks (CDN) serve a large portion of all internet traffic today. You likely interact with CDNs all the time without even realizing. Think loading content on the web, like streaming Netflix or loading webpages.
A CDN’s purpose is to solve one key problem – latency. They do this by minimizing the distance between your users and your website’s server by distributing your content to edge servers all over the world and then acting as the middle man between your end users and the server hosting your website (called the origin).
The CDN has hundreds of edge servers distributed all over the globe which cache your web content as it’s loaded.
The diagram illustrates the distribution of all the edge servers CloudFront has available to easily serve your content.
Instead of a user directly loading pages on your website from the origin, which may be far from the user geographically, they request the website from the CDN which identifies the edge server closest to the user as the server that will serve the content.
Imagine your website is hosted in the US. There will be significant latency introduced when a page is loaded from Europe or Asia, when compared to the load time if the user is already in the US and near server hosting your website. The CDN aims to shorten the physical distance the request must travel in order to decrease the time it takes to load the page.
This is all unbeknownst to the user, of course, who simply requests the site through your domain name. The user can’t tell if you are using a CDN.
When a file is requested, if the edge server closest to the user has already loaded the page or file recently, it returns it immediately. If it had not loaded that item recently, it loads it from our server and then stores it for the next user from your region who requests the same page or file.
CDNs are easy to install and can immediately provide significant performance boosts if you have international users browsing your site(s).
Content Bloom has experience with pretty much all of the major CDNs across our web implementations and each has its advantages. Lately, our work Amazon’s CDN offering – AWS CloudFront – has us singing its praises.
Here are 4 reasons I love working with CloudFront.
It’s affordable, easy to navigate, and comes with no strings attached
The value proposition is simple – if you have users accessing your website from all over the planet, and not just a single geographic region, a CDN is likely the easiest and most effective way to increase site performance.
Some competitors require signed contracts, but you can spin up CloudFront distributions on the fly in minutes and are only charged for the bandwidth you use.
And, most importantly, it’s easy to work with. You simply create a CloudFront distribution through the AWS interface and then create an alias record that points to your CloudFront distribution instead of your website. The CloudFront distribution acts as a proxy, sending requests to your origin servers and caching the results.
On top of being easy to work with, it’s also highly programmable, which brings me to my second point.
Easily programmable through SDKs and APIs
One of the things we love the most about CloudFront is how simple it is to write custom code against CloudFront events such as incoming or outgoing requests using AWS Lambda, Amazon’s serverless compute platform. With Lambda, it’s easy to hook up code to perform actions on requests passing through CloudFront such as:
- Perform redirects on incoming URLs
- Check incoming request for authentication tokens in request headers
- Invalidate the entire CDN cache when a file is updated on your website
With Lambda and Lambda@Edge you can write, upload, and globally distribute your code to all 180 edge nodes in minutes. Testing tools are built-in to the platform, making writing and distributing the code a breeze.
Image source: https://aws.amazon.com/lambda/edge/
Tip: All of the commands and configurations made in the AWS interface can be automated using the AWS SDK. You can also use this to hook-up Lambda & CloudFront to your CI/CD pipeline.
Add another level of redundancy to your web stack
When CloudFront is configured, you must provide an origin. As mentioned above, this is the server where CloudFront will load your web content. Now imagine your origin server, which communicates with the CDN, goes down. Even though the CDN may be able to temporarily serve incoming traffic, it will shortly start failing once the caches begin expiring.
CloudFront makes it simple to add another layer of redundancy to your website. You can configure a failover origin, so that if CloudFront fails to receive a response from your first origin, it will begin requesting content from the failover origin. This removes another single point of failure in your web stack at the network level.
The diagram above illustrates how CloudFront can be setup to redirect traffic from Origin Server A if it has an issue, or the website crashes. In this scenario, traffic will be automatically rerouted to Origin Server B.
Note: A key architecture principle in web development is to eliminate all single points of failure. A single point of failure is any one part of your web stack which would cause the website to go down if it crashed or was taken out.
Benefit from Amazon’s security and compliance
Some of the largest websites in the world run on CloudFront and leverage its security features. Why wouldn’t we want to take advantage of all of the money, effort, and time the AWS team put into their platform and benefit from economies of scale?
Because CDNs are deployed on the edge of your network, a CDN can provide additional security by acting as a fence around your website. It can intercept requests before they reach your websites server, reducing load on your servers while also providing additional security at the network level.
Amazon provisions specific tools and technologies into their web stacks to protect against all forms of modern web attacks. Tools like AWS Shield aim to provide additional layers of security at the network level around web attacks such as direct denial of service attacks, blocking the attacks before they get to your application.
Let Amazon do the heavy lifting when it comes to security and, instead, focus on things adding direct value to your organization.
We’re not done just yet! There are other reasons to leverage a CDN:
- Improve performance by decreasing latency
- Take load off your servers allowing you to handle more traffic
- Block web attacks at the network level
- Easily setup load-balancing and failover redundancy
CloudFront is an industry leader in the CDN space and we’re looking forward to see where Amazon takes it.