Content Delivery network
Content Delivery Network
Content Delivery Network (CDN) is a globally distributed network of caching servers that provides web-pages, images, videos, and other content, very close proximity to user.
For this achieve, CDN uses DNS geolocation function, to determine, the geolocation of each requested web-pages or content and then they forward the request to nearest caching servers to fulfill the client demand.
Amazon Cloud Front is the AWS global content delivery network service, that accelerates the distribution of web content to users based on their location. Let’s discuss more about it.
AWS CDN: Amazon Cloud Front:
Amazon Cloud Front is used to deliver your web content using Amazon Global network of Edge locations.
Whenever user request any content, using cloud front URL, user request is routed to edge location that provides the lowest latency. IF the content is currently not available in that edge locations, AWS CloudFront retrieves it from the origin server and forwards the content to user and side by side also cache it locally.
Amazon CloudFront is optimized to work with other AWS cloud services like S3 Buckets, S3 Static Websites, EC2 Instances, Elastic Load Balancing, Route53 etc. It also works well with non-AWS origin servers like On-Prim Web servers.
Amazon CloudFront supports all content that can be served over HTTP or HTTPS.
Amazon CloudFront Concepts Deep dive:
There are three main concepts that you need to understand in order to implement or start using Amazon CloudFront.
- Cache Control
In order to use the cloud front, we need to create a Distribution. A Distribution is identified by a DNS domain name such as d234abcd.cloudfront.net. In order to serve files from Amazon CloudFront, you simply use the distribution domain name in place of your web-site domain name and rest of the file path where content is stored.
You can use the same Distribution Domain name or make it more friendly by creating CNAME in Amazon Route 53, that will point to same CloudFront domain name created by you.
When we create a distribution, we need to specify DNS domain name of the origin, that is S3 Bucket or HTTP server, from where Amazon CloudFront will retrieve the objects (Web files) and send to you.
Some example of Origin DNS domain names:
- Amazon S3 Bucket: dclessonsbucket.s3.amazonaws.com
- EC2 instance: ec2-102-0-112.compute-1.amazonaws.com
- Website URL: aws.dclessons.com
Once the content requested is served from an Edge location, the object stay in cache until they expire. By default, objects expire from cache after 24 hrs. As soon as the object expire and then for any further request for same object, CloudFront goes to origin server to retrieve the objects and verify that objects is unchanged or to fetch a new version of objects of it has changed.
You can control how long objects can stay in Amazon CloudFront Cache before expiring. In order to do that, you can choose to use Cache-Control headers set by your origin servers or you can set minimum, maximum and default time to Live TTL for objects in your Amazon CloudFront Distribution.
The best practice to use a version identifier as part of the object (file) path name. lest see an example:
- Old File: dclessons/v1/css/dclessons.css
- New File: dclessons/v2/css/dclessons.css
When we use Versioning. user will see the latest content through Amazon Cloud Front, old versions will expire from the Cache Automatically.