# 3.6 CloudFront

## What is CDN

A Content Delivery Network is a system of distributed servers (network) that deliver webpages and other web content to a user based on the geographic locations of the user, the origin of the webpage and a content delivery server.

## What is CloudFront

Amazon CloudFront deliver your content which stored in any Origin or any non-AWS origin server through Edge Locations, so that people can access your content quickly through Edge Locations.

Amazon CloudFront can be used to deliver your entire website, including dynamic, static, streaming, and interactive content using a global network of Edge Locations. Requests for your content are automatically routed to the nearest Edge Location, so content is delivered with the best possible performance.

Amazon CloudFront is optimized to work with other Amazon Web Services, like S3, EC2, Elastic Load Balancing, and Route53. Amazon CloudFront also works seamlessly with any non-AWS origin server, which stores the original, definitive versions of your files.

In short, Amazon CloudFront is a service which can utilize Edge Locations as caches to serve your Origin or server to clients. The "cache" here doesn't mean the cache (Memcached or Redis) which is located between the web app server and database, but the Edge Locations which is located between the Origin (server) and the client browsers.

## Key Terms

* Edge Location: this is the location where content will be cached. This is separate to an AWS Region/AZ. About 50 Edge Locations in the world.
* Origin: this is the origin of all the files that the CDN will distributed. This can be either an S3 bucket, an EC2 instance, an Elastic Load Balancer or Route53. Non-AWS origin server can also be origins.
* Distribution: this is the name given to the CDN which consists of a collection of Edge Locations. There are two kinds of distribution: Web Distribution, typically used for websites; RTMP (Real-Time Messaging Protocol), used for Media Streaming (adobe, flash, etc).

## Tips you should know

* Edge Locations are **not** just READ only, they can be written by Origins, servers or clients. For example, put an object on to them, and these objects will be put and back up to original Origin or server, so these objects will be replicated to the Origin.
* Objects are cached for the life of the Time To Live (TTL).
* You can clear cached objects, but you will be charged. Objects will automatically expire after the TTL. However, when you have a big update on your objects at origins, you will need to clear the previous objects from Edge Locations and then deliver the updated objects.

## Benefits of using CloudFront

Amazon CloudFront is an easy, self-service way to distribute content to end users with **low latency** and **high data transfer speeds**. It can also be used to stream media to viewers across the globe. Because the Edge Locations are located in different locations of the world, so CloudFront can deliver **customized** and personalized content to each country, furthermore, to each user.

## Who is using CloudFront

The developers who need a easy and cost-effective way to distribute content with low latency and high data transfer speeds are using it. For example, E-commerce and travel web applications that are highly personalized. Fast discovery of products, via search and browse, is critical, since their site performance often translates directly into revenue and end user loyalty. Media and Entertainment is another area, they can use CloudFront to stream videos or live events to their global viewers. Content need to be customized to each user, so this content can be cached in CloudFront for short periods of time. Advertising service and social media can also use CloudFront.
