Introduction to Amazon Cloudfront and its architecture
1. What is Amazon Cloudfront?
If you have a website with users from all over the world, there will be a problem with your users who are too far away from where your server is located. They will have to wait a long time to receive a response from the website.
CDN stands for Content Delivery Network. CDN is a network of many servers located in different parts of the world. These servers store copies of the content of your Website in order to distribute to nearby users. Amazon CloudFront is one of the world's largest CDN systems.
We have two terms here:
Origin Server
Origin Server: This is where your original files are placed. It can be an HTTP Server, Amazon S3 Bucket, etc.
Edge Location (POP - Point of Presence)
Edge Location is also known as POP (Point of Presence) where the user's requests will be sent to. Note that requests of the user will not be sent to the Origin Server directly.
Let's take a look at the illustration below. We are going to see how Cloudfront works when the user requests a file from your website:
1- The user accesses your Website and requests a file such as an image file or HTML, etc.
2 - DNS routes the request to the fastest responsive POP (Edge Location) (minimum latency). Normally, a POP with the closest geographical location to the user, and it will serve the user's request.
3 - At POP (Edge Location), CloudFront will check its cache to see whether or not the file requested by the user is available. If yes, the file will be returned to the user. However, if the file is not in the cache, CloudFront will perform the following steps:
- 3a - CloudFront will send a request to Origin Server to get the file.
- 3b - Origin Server will send the file to Edge Location.
- 3c - As soon as the first bytes of data from the Origin Server are sent to the Edge Location, they will be sent to the user. Moreover, CloudFront adds this file to the Edge Location cache for the next service in case someone requests the file next time.
2. New architecture of CloudFront
Amazon upgraded CloudFront architecture in November 2016. Here is an illustration of the difference between old and new architecture.
We can see the presence of the Regional Edge Cache in the new architecture.
As for the new CloudFront architecture, what will happen if the user requests a file from your website?
1 - A user accesses your website and requests a file such as an image file or HTML, etc.
2 - The user's request will be sent to the fastest responsive POP (Edge Location) (minimum latency).
3 - At POP (Edge Location): if the requested file exists in the POP cache, it will be returned to the user. Otherwise, CloudFront will perform the following steps:
- 3a - CloudFront will forward the request to Regional Edge Cache.
- 3b - If the file exists on the cache of Regional Edge Cache, it will be sent to Edge Location. Otherwise, it forwards the request to the Origin Server (...)
- 3c - As soon as the first bytes of data from the Regional Edge Cache are sent to the Edge Location, they will be sent to the user. Moreover, CloudFront adds this file to the Edge Location cache for the next service in case someone requests the file next time.
Regional Edge Cache has a much larger cache than a single Edge Location, so it stores files including less common ones longer. While Edge Location has a smaller cache, so common files will be stored for a long time. Over time, if a file becomes less common, it will be removed from the cache of Edge Location.
The presence of Regional Edge Cache cuts back on requests sent to Origin Server.
3. Edge Locations Map
The map below shows you the geographical locations of Edge Location(s) and Regional Edge Cache(s) in the world:
4. Invalidation
When a file is stored on the Edge Location (or Regional Edge Cache), it will have a validity period (How long it is in the cache). If before the validity period ends, the user gets access to it, this validity period of the file will be reset from the beginning, otherwise, the file will be removed from the cache.
Note: The validity period of files on the Regional Edge Cache is much longer than that of files on the Edge Location.
If you change the content of a certain file on the Origin Server, the user may not be able to access the new content as CloudFront will send the user the old version of the file if it is in the cache.
You can send an Invalidate request to CloudFront to tell CloudFront to delete a list of certain files from the cache of all Edge Location and Regional Edge Cache.
Amazon Web Services Tutorials
- Introduction to Amazon Web Services (AWS)
- Introduction to Amazon S3
- Introduction to Amazon Cloudfront and its architecture
- How to reduce Amazon Cloudfront Costs?
- Amazon CloudFront Invalidation
- Introduction to DigitalOcean Spaces
- Create DigitalOcean Spaces Bucket
- Introduction to Amazon ACM
- Java Awssdk S3 S3Client Upload object
- Create AWS accessKeyId/secretAccessKey
- Java Awssdk S3 List objects
- Host a static website on Amazon S3
- Java Awssdk CloudFront Invalidation
- DigitalOcean Spaces Create Access Key
- Java Awssdk Common Credentials Providers
- Java Awssdk ProfileCredentialsProvider
- Java Awssdk Creating and using EnvironmentVariableCredentialsProvider
- Java Awssdk Creating and using SystemPropertyCredentialsProvider
- Java Awssdk S3 Upload object with S3TransferManager
- Java Awssdk S3 S3TransferManager download object
- Java Manipulate DigitalOcean Spaces using S3TransferManager
- Java Create, list and delete S3 Bucket
- Aws Console create IAM User
- Create Amazon S3 Bucket
- Configure custom domain for Amazon S3 static website
- Create a CloudFront distribution for S3 Bucket
- Configure Amazon CloudFront Error Pages
- Amazon S3 Bucket policies
- Amazon AWS Policy Generator - policygen
- Migrate DNS service to Amazon Route 53
- Transfer domain registration to Amazon Route 53
- Request an SSL certificate from Amazon ACM
Show More