AWS Cloud Front
Amazon Cloud-Front is an AWS Content Delivery Network service which is used to deliver the user content at a much faster speeds hence enhancing the user experience. Cloud Front is used to deliver the web content to the users based on the geographic location of user and the origin of the webpages.
Suppose you have a Webserver located in London and have a user base accessing that webserver content from across the world. For the users who access the content from UK will have high speed access to the content while for the users far from UK e.g. in Australia the speed of accessing the content would be much higher resulting is poor user experience.
This is where the Cloud-Front CDN service from AWS can help. Cloud Front delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you’re serving with CloudFront, the user is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.
- Edge Locations: AWS Edge Locations are the group of geographically spread DCs where the contents are cached. It isn’t the same as AWS Availability zone. Edge locations aren’t Read-Only, you can also write the content to the edge locations. Objects are cached on the Edge Locations with a TTL value.
TTL specifies how long the object stays up in the cache at Edge Location. Until the TTL expires all requests for the content are served by the Edge locations. If the TTL expires and a new access request for the content comes in the Edge location will go to the Origin to verify if it has the latest version of the File/Object.
- If the CloudFront cache already has the latest version, the origin returns a status code 304 Not Modified.
- If the CloudFront cache does not have the latest version, the origin returns a status code 200 OK and the latest version of the file.
By default all the files cache duration is 24hrs, but AWS provides you with a number of options to play with the TTL timer setting with Min., Max., & Default Cache Timers.
- Origin: It refers to the Origin of the files that the users access from the CDN cache. The origin of such files could be an S3 bucket, EC2 instance etc.
- Distribution: This is the name provided to the CDN consisting of the collection of the edge locations.
There are two types of Distribution available on AWS CloudFront:
- Web Distribution: Used for Websites
- RTMP: Used for Media Streaming
How CloudFront Works:
Step 1: Users places a request to access some Web content, an image for an example.
Step 2: The request goes to the DNS server or Route53 (Will cover in another post), the DNS server then routes the request to the nearest Edge Location.
Step 3: The cache at the Edge Location is checked if it has the requested Object.
- If the object is there in the Cache the response is sent back to the user immediately and he is able to access the requested image.
- If the object file isn’t present in the cache at Edge Location, then the Edge Location will download the file from the Origin via the Amazon’s High Speed Backbone Network and will download the Object and thereon store it in its cache for a default period of 24 hrs. Any subsequent request to access the same content shall be server by the Edge Location.