Solution to the Problem of Latency through an AWS Service : Cloud Front

Anshika Sharma
7 min readJun 9, 2020

--

Any of the services which we are getting in the Market are all based on some use-cases, some challenges and in order to solve these challenges these services has been created. Cloud Front is one of them, that has been created to solve the problem of latency in accessing the data from a distant servers. For this we will learn about different concepts like CDN, Edge Location, etc.

We have some requirements for this, you must be gone through the following story

Now we will go through each and every term used in creating a setup for cloud Front with an example altogether.

We know that AWS has its Data Center at different places all over the world, One of the place is Mumbai also. It is designed in such a way that clients will not face any latency problem like if a client is near California so he can use that data center and can work easily with its resources, also if a person is from India he may use the Data center in Mumbai . But is it really working for such regions like Delhi, Rajasthan, etc(some places in India). Its true that it is not possible to setup the Data Centers so for this there is a solution for this , which is the concept of CDN through Edge Locations.

Console Window of AWS

Now if we create an Instance and try to access the Instance , i.e.,

New Instance Created

Now we will setup web server in our Instance and then create a web page in it

Connecting to the Instance through SSH

Here we used SSH we can also use PuTTY in place of SSH

Entered into the Instance

To install anything in our OS or Instance we need to move to the root user.

Switched to root user
Setup of web Server
Default folder of web server
Code for Web Server

For accessing our web server we need to start the service of web server, i.e.,

Starting the Web server service

On accessing the web page through the IP, we will get the output but will take some time :

Taking time to load

Here we get the output :

Our Web page

Hence, we can see that this is taking time to get the output from the Availability Zone. So there is a solution to this problem, i.e., Edge Location based on CDN (Content Delivery Network).

What is Edge Location?

An edge location is where end users access services located at AWS, the cloud computing division of US-headquartered Amazon. They are located in most of the major cities around the world and are specifically used by CloudFront (CDN) to distribute content to end users to reduce latency.

In simple words,the locations where we can access the services at single time and the end user can use these services for multiple times so that the user need not to send the packets to Mumbai every time when they access the services.

As the Latency problem arises due to large regional distances. This above network designed in such a way that we are setting up a small data center at Delhi , is called as Edge Location. Here also we will try to setup such a network that will only transfer the required data from the Availability zone. Now we can also define the term CDN (Content Delivery Network), it is the network through which we transfer the required data or services from the Availability zone to some specific Edge locations in order to reduce the Latency problem and provide the clients an easy and Fast access to resources.

A Content Delivery Network

There is program behind Edge Location, through edge location it will take request to the Availability Zone and the Availability Zone will transfer the required data or services to the Edge location. Now this Edge Location will store a copy of this Accessed data in its local storage, so that when the client go to this edge location, and request for accessing the same data or services they can access it from the local copy.

-> When they find the local copy, that means they hit.

-> When they don’t find the local copy, that means they missed.

Edge Location is also known as Proxy Setup. By default the time for local copy is 1 day, but we can also change this default time. From where we are accessing the data, that is known as origin.

Here we are going to access the data from the Web server, this means the web server is origin. Amazon set such a system that it provide a single URL and when any client type this URL, this URL will automatically identify that which edge location has requested and it automatically allocate the nearest edge location to it or nearest Availability Zone to it. This intelligence is provided through a service called DNS(Domain Name System). This system provide Fault Tolerance.

The process of sending request to web server for data access is known as Forwarding.

Distribution Setup

This setup is known as Distribution and it provide CDN.

We will complete this setup step by step:

  1. Go to Cloud Front, a service of Network & Content Delivery :
CloudFront Service

2. For Creating Distribution, click on Create Distribution :

CloudFront Distribution window

3. Fill all the details to create the distribution, In origin name, we will add the DNS name of web server :

DNS name of Instance
Origin Domain Name Details
Viewer Protocol Policy (Redirect HTTP to HTTPS)
Click on create Distribution
Created Distribution

4. We can check all the Details of the Distribution here :

Details About Distribution

5. Access the Web Server through the DNS that CloudFront Provided :

Web Page through CloudFront DNS

Here, we seen Viewer Protocol and Origin Protocol. The main difference between these two protocols is

  1. The viewer protocol works in between client and edge location (through https).
  2. The Origin Protocol works in between edge and origin(here our origin is EC2 instance) through http.

So, we have successfully accessed the web server through CloudFront DNS URL. But if we think in such a way that what happen if developer change some layout or something in the web page, then does these changes will accessed at the client side at the same time?

The Answer is No. Its true that we can’t access the changes at the same time because the TTL time or the Updation time of Edge location is 1 day(by default) so the updates will be accessed after one day only. For this also we have a option of Invalidation.

We want whatever changes we make at origin, that will be updated all over the edge locations, and the cache should also be removed.

Invalidation is the concept in which the objects can remove the cloudfront edge cache data. We use (*) to delete everything. After applying the Invalidation for everything , Distribution edge need to forward the request for the data and access the data from the origin.

For creating an Invalidation, we go the created distribution and see the current Distribution settings and click on Create Invalidation ,

Creating Invalidation
Mention the object Path, which need to be Invalidate
Invalidation Created

Details about Invalidation can be accessed from Details

Invalidation Details

Now, we will make some changes in the code of web page

Changes in the Web Page code

Try to access the Web Page now through the DNS URL of Cloud Front :

Updated Web Page

We have successfully accessed the updated web page at the same time with the help of Invalidation Concept. This is how AWS provide a CDNaas (Content Delivery Network as a Service), CloudFront.

Just like CloudFront we have a lot of services that are provided by AWS to solve many problems in real time and they have many efficient and interesting use cases. In further blogs we will discuss about more and more use cases and the services helpful for them.

Thank you.

--

--

Anshika Sharma
Anshika Sharma

Written by Anshika Sharma

I am a tech enthusiast, researcher and work for integrations. I love to explore and learn about the new technologies and their right concepts from its core.

No responses yet