Create a global presence with Content Delivery Networks
17 Aug 2020
Content delivery networks (CDNs) are not new but they are, for most, under appreciated and under used.
In the case of Amazon’s CDN offering, Cloudfront, the service, is nothing short of being a technical marvel, and is possibly the most important piece of web infrastructure that any business could employ.
To explain why, we first need to look at the basic principles of a CDN.
Conventional web set-ups meant that your web server dealt directly with your website visitors. If your server is in London and your visitor is in Australia, each request may result in 5-10 seconds of delay, as that request traverses the planet, being bounced through many relays along the way.
In addition, your server may be able to handle requests from one hundred concurrent users, but would crash if there were two hundred. If you increase your server capacity (at great expense), it may be underused for most of the time and would still have limits.
CDNs consist of ‘edge’ locations– servers located globally. Below is a map showing Cloudfront’s edge locations.
When you employ a CDN, you point your website’s domain name to the CDN and tell the CDN where to find the ‘origins’ - servers or file stores, holding your webpages, images or videos.
When a visitor types in the domain of your website, Cloudfront sends their request to the nearest edge location. The webpage or image will be stored in that edge location, if it has been requested previously. If it is the first time, the request will have to go to the origin, but all subsequent requests will go to the edge location where it will be cached for fast retrieval.
The concept is fairly straightforward, albeit there are other requirements. First one to consider, is that not all content is static – the CDNs need to be configured to selectively cache items and this will be unique to each use case. Also, cached content needs to reflect any changes to content in the origin and there are various ways in which this can be accomplished.
Once set up, the immediate benefits become clear.
CDNs offer a consistent page load speed to all visitors, regardless of their location.
Search engines see that your content is being served locally and SERPs in other territories will improve accordingly
CDNs can handle enormous visitor numbers, so provided content is cached or at least cacheable, high traffic will not impact your server.
Cached content will be available even if your server is offline. For most use cases, this represents a massive increase in availability.
CDN costs are charged by data going out to end users, and these costs are usually small and massively lower than the costs required to create the same degree of availability and resilience, using multiple webservers.
And that’s just for starters!
There is a lot more to Cloudfront than plain old content delivery.
Cloudfront integrates seamlessly with Amazon’s serverless technology, Lambda, to provide localised computing functions at edge locations.
Lambda@edge can be triggered in one of four ways – the viewer request, viewer response, origin request and origin response.
The first and most commonly employed trigger, the viewer request, is another area where Cloudfront excels. Cloudfront can give you a lot of information in the viewer request including the viewer’s location, their time zone, their screen size, the browser they are using, and more.
Armed with this information, we could have a hypothetical scenario where there is a single brochure download link on a website. The brochure has three locale specific variants and there are high and low resolutions of each.
Cloudfront lets us identify the viewer’s location and their device screen size from the viewer request, and the request triggers our Lambda@edge function which uses the location and device screen size, to determine which brochure the visitor should get and serves the appropriate brochure.
You can read more about serverless computing in our previous article.
Like Cloudfront, Lambda will not be overrun by spikes in your visitor traffic, and because the computing is carried out at edge, it is lightning fast.
And we’re still not done with Cloudfront!
Cloudfront has some great inbuilt features, such as being able to compress your files to further speed up your website or optimise your files for smooth streaming. Cloudfront can redirect your traffic to HTTPS, implement headers, allow you to set up to twenty-five separate behaviours, serve custom error pages and much more.
Cloudfront works well with external or on-premise resources but is at its best with other AWS services, making it so simple to provision SSL certificates from Certificate Manager, point domains from Route 53, set origins from load balancers, EC2 instances and S3 buckets and as with all AWS services, every function and feature is exposed through APIs as well as through the web console.
In conclusion, Cloudfront is quite simply a must have for all websites. There are other CDNs and for the most part, their ability to deliver content will be comparable, but when it comes to full technology stack integration, there really is no comparison.
Cloudfront has a minimal cost, and if implemented correctly, will save money, while giving your websites and applications true global coverage (including mainland China), almost total resilience and availability, extreme load capacity and a simple route into serverless computing capabilities.
For help with content delivery network and other digital transformation technologies, please contact us to talk to one of our expert consultants.
Cloudfront map and viewer response images from Amazon Web Services