AWS Builder Center
๐ŸŒ Day 14/30: CDN & Amazon CloudFront โ€” How Do We Make Cloud Applications Faster? โšก

๐ŸŒ Day 14/30: CDN & Amazon CloudFront โ€” How Do We Make Cloud Applications Faster? โšก

Our college portal can now handle thousands of users with Auto Scaling, but students far from the application servers still experience slower content delivery. ๐Ÿค” How can CDN caching and Amazon CloudFront bring frequently requested content closer to users, and which content should we cache โ€” a college logo, a public study PDF, or a student's private exam result? ๐Ÿ’ฌ

Series: Cloud Computing (25 articles)

  1. โ€ฆ
  2. 15
    ๐ŸŒ Day 14/30: CDN & Amazon CloudFront โ€” How Do We Make Cloud Applications Faster? โšก This article
Tech Enthusiast | Exploring AWS, Data Structures & Web Dev

๐ŸŒ Day 14/30: CDN & Amazon CloudFront โ€” How Do We Make Cloud Applications Faster? โšก

๐ŸŽฎ Mission 14: Bring the Content Closer!

Yesterday was a huge success.
Our college examination portal learned how to scale automatically.
When thousands of students arrived:
1
2
3
4
5
6
7
8
9
10
11
12
๐Ÿ‘จโ€๐ŸŽ“ ๐Ÿ‘ฉโ€๐ŸŽ“ ๐Ÿ‘จโ€๐ŸŽ“ ๐Ÿ‘ฉโ€๐ŸŽ“
|
v
โš–๏ธ Load Balancer
|
v
๐Ÿ“ˆ Auto Scaling
|
+------------+------------+
| | |
v v v
EC2-1 EC2-2 EC2-3
More users?
โžก๏ธ More EC2 instances.
Fewer users?
โžก๏ธ Fewer EC2 instances.
Everything looked great.
But the next morning, Rahul received a message from his friend:
โ€œThe portal worksโ€ฆ but why does it take so long to load?โ€ ๐Ÿ˜•
Rahul checked the servers.
Everything was healthy.
The Load Balancer was working.
Auto Scaling was working.
The database was working.
So what was slowing things down?
The cloud architect smiled.
โ€œOur application can handle more users. Now we need to make it faster for users who are far away from our servers.โ€
And that brings us to today's mission.

๐ŸŒ Content Delivery Networks โ€” CDN


๐Ÿƒ 1. Imagine a College With One Library

Let's forget cloud computing for a moment.
Imagine your college has one central library.
The library is located in Delhi.
Now imagine a student living in Mumbai wants the same textbook.
The student has to request it from Delhi every time.
1
2
3
4
5
6
7
8
Mumbai Student
|
| Long distance
v
Delhi Library
|
v
Book ๐Ÿ“š
It works.
But it's not the fastest approach.
Now imagine the college keeps popular books in smaller libraries closer to students.
1
2
3
4
5
6
7
8
9
๐Ÿซ Central Library
|
+---------+---------+
| |
v v
Mumbai Library Jaipur Library
| |
v v
Student Student
Now students can get popular content from a nearby location.
That's the basic idea behind a Content Delivery Network (CDN).

๐ŸŒŽ 2. What Is a CDN?

A Content Delivery Network is a distributed network of locations that can serve content closer to users.
Instead of every user requesting every piece of content from the application's original server, frequently requested content can be cached at locations closer to users.
Think:
1
2
3
4
5
6
7
Without CDN

User
|
| Long journey
v
Origin Server
versus:
1
2
3
4
5
6
7
8
With CDN

User
|
v
Nearby CDN Location
|
+---- Cached Content
The shorter journey can mean lower latency for cached content.
And that can make websites feel much faster.

๐Ÿง‘โ€๐ŸŽ“ 3. Back to Our College Portal

Let's look at our examination portal.
Students don't only request examination data.
The website also contains many static files.
For example:
  • ๐Ÿ–ผ๏ธ College logo
  • ๐ŸŽจ CSS files
  • โš™๏ธ JavaScript files
  • ๐Ÿ“ธ Images
  • ๐Ÿ“„ Public study material
  • ๐Ÿซ College banners
  • ๐Ÿ“ฑ Website assets
Imagine thousands of students requesting the same college logo.
Do we really need every student to travel all the way to our application server just to download the same image?
Not necessarily.
A CDN can cache content and serve subsequent requests from a location closer to users.

โšก 4. Meet Amazon CloudFront

AWS provides a CDN service called Amazon CloudFront.
CloudFront uses a global network of edge locations to deliver content closer to users.
Our architecture can now evolve.

Before:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
๐Ÿ‘จโ€๐ŸŽ“ Students
|
v
๐ŸŒ Internet
|
v
โš–๏ธ Load Balancer
|
v
๐Ÿ“ˆ Auto Scaling
|
+---------+---------+
| | |
v v v
EC2-1 EC2-2 EC2-3

After adding CloudFront:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
๐Ÿ‘จโ€๐ŸŽ“ Students
|
v
๐ŸŒ Amazon CloudFront
|
+---------+---------+
| |
Cached Content Origin
| |
v v
Student Load Balancer
|
v
Auto Scaling
|
+-----+-----+
| |
v v
EC2-1 EC2-2
Now our architecture has another important layer.

๐Ÿง  5. What Is Caching?

Caching sounds complicated.
It's actually a very simple idea.
Keep a copy of frequently requested content so it can be delivered faster next time.
Imagine Rahul downloads the college logo.
The first request may need to retrieve the logo from the origin.
1
2
3
4
5
6
7
8
9
10
Rahul
|
v
CloudFront
|
v
Origin
|
v
College Logo
CloudFront can cache the response according to the configured caching behavior.
Then another student requests the same content.
1
2
3
4
5
6
7
Student 2
|
v
CloudFront
|
v
๐Ÿ“ฆ Cached Logo
The request can be served from the cache without going all the way back to the origin.
That's called a cache hit.

๐ŸŽฏ 6. Cache Hit vs Cache Miss

Let's learn two important terms.

๐ŸŸข Cache Hit

The requested content is already available in the cache.
1
2
3
4
5
6
7
8
9
10
Student
|
v
CloudFront
|
v
๐Ÿ“ฆ Content Found!
|
v
Student gets content โšก
This can be fast because the content is served from the CDN cache.

๐Ÿ”ด Cache Miss

The requested content isn't currently available in the cache.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Student
|
v
CloudFront
|
| โŒ Not in cache
v
Origin
|
v
Content
|
v
CloudFront
|
v
Student
The CDN retrieves the content from the origin and can cache it according to the configured rules.
Future requests may then be served from the cache.

๐Ÿ—บ๏ธ 7. Why Does Location Matter?

Let's imagine our application origin is running in one AWS Region.
A student near that Region may experience relatively low network latency.
But another student could be thousands of kilometers away.
1
2
3
4
5
6
7
8
9
10
11
Student A
|
| Shorter network distance
v
CloudFront / Origin

Student B
|
| Much longer network distance
v
CloudFront / Origin
A CDN helps by distributing cached content across a global network.
Instead of making every user communicate directly with the origin for every cacheable object, users can often receive cached content from a nearby CloudFront edge location.
This is especially useful for content that is:
  • Frequently requested
  • Cacheable
  • Relatively static

๐Ÿซ 8. Our College Portal Gets Faster

Let's look at a realistic example.
Our college website has:
1
2
3
4
5
college-logo.png
college-banner.jpg
styles.css
app.js
exam-guidelines.pdf
Thousands of students request these resources.
CloudFront can cache appropriate objects.
So our architecture becomes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
๐Ÿ‘จโ€๐ŸŽ“ Students
|
v
๐ŸŒ CloudFront
|
+-------------+-------------+
| |
v v
๐Ÿ“ฆ Cached Assets Origin
| |
| v
| โš–๏ธ Load Balancer
| |
| v
| ๐Ÿ“ˆ Auto Scaling
| |
| +--------+--------+
| | | |
| v v v
| EC2-1 EC2-2 EC2-3
| |
| v
| Database
|
v
Fast Content Delivery โšก
Now the architecture has a separation of responsibilities.
CloudFront:
โ€œI'll help deliver cacheable content closer to users.โ€
Load Balancer:
โ€œI'll distribute application traffic.โ€
Auto Scaling:
โ€œI'll adjust the number of application instances.โ€
EC2:
โ€œI'll run the application.โ€
Database:
โ€œI'll store application data.โ€
That's cloud architecture thinking. ๐Ÿง 

๐Ÿšจ 9. But Waitโ€ฆ Should We Cache Everything?

This is where things get interesting.
Imagine Rahul logs into the examination portal.
He sees:
1
2
Rahul's Result
95%
Should we blindly cache that page and show it to another student?
๐Ÿšจ Absolutely not!
That could become a serious security and privacy problem.
Personal or dynamic information often needs very different caching behavior from public static content.
For example:

Good candidates for caching

1
2
3
4
5
College Logo
CSS
JavaScript
Public Images
Public Static Files

Requires careful handling

1
2
3
4
5
Student Exam Result
Personal Profile
Payment Information
Private Dashboard
Authentication Responses
The exact caching strategy depends on the application's behavior, headers, cache policies, and security requirements.
The important lesson is:
Fast does not automatically mean safe.
We must design caching carefully.

๐Ÿงฉ 10. CDN vs Load Balancer

A common beginner question is:
โ€œWaitโ€ฆ aren't CloudFront and a Load Balancer doing the same thing?โ€
No.
They solve different problems.

๐ŸŒ CDN

Main purpose:
Deliver content efficiently from locations closer to users.
Think:
โ€œWhere can I get this content fastest?โ€

โš–๏ธ Load Balancer

Main purpose:
Distribute application traffic across healthy backend targets.
Think:
โ€œWhich application server should handle this request?โ€

Together

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
๐Ÿ‘จโ€๐ŸŽ“ Users
|
v
๐ŸŒ CloudFront
|
+-------+-------+
| |
v v
๐Ÿ“ฆ Cached Content โš–๏ธ Load Balancer
|
v
๐Ÿ“ˆ Auto Scaling
|
+-----------+-----------+
| | |
v v v
EC2-1 EC2-2 EC2-3
This is much more powerful than using either component alone.

๐ŸŽฎ 11. The College Portal Story Continues

It's 10:00 AM.
Students from different cities are accessing the examination portal.
Rahul is in the college campus.
His friend is in Jaipur.
Another student is visiting family in Mumbai.
They all open the same portal.
The request path might look conceptually like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
๐Ÿ‘จโ€๐ŸŽ“ Student
|
v
๐ŸŒ CloudFront
|
+----> ๐Ÿ“ฆ Cache Hit
| |
| v
| Fast Response โšก
|
+----> โŒ Cache Miss
|
v
โš–๏ธ Load Balancer
|
v
๐Ÿ“ˆ Auto Scaling
|
+-----+-----+
| | |
v v v
EC2 EC2 EC2
|
v
Database
Now the architecture is doing something clever.
Static or cacheable content can be served from the CDN.
Dynamic application requests can continue to reach the application infrastructure.

๐Ÿ“ฆ 12. What Exactly Is the Origin?

You may have noticed a new word:
Origin
The origin is the source from which CloudFront retrieves content when it isn't available in the cache.
Depending on the architecture, an origin could be something such as:
  • An Amazon S3 bucket
  • An Application Load Balancer
  • Another supported HTTP endpoint
For our college portal, we might have:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CloudFront
|
+---------+---------+
| |
v v
Amazon S3 Load Balancer
Static Content Dynamic App
| |
| v
| Auto Scaling
| |
| EC2
|
v
Images / Assets
This is a powerful pattern.

๐Ÿชฃ 13. CloudFront + Amazon S3

Remember Day 8?
We learned about Amazon S3.
S3 is excellent for object storage.
Now we can combine it with CloudFront.
Imagine our college stores:
1
2
3
4
college-logo.png
exam-banner.jpg
study-material.pdf
course-image.png
inside S3.
CloudFront can be placed in front of the content delivery path.
Conceptually:
1
2
3
4
5
6
7
8
9
10
Students
|
v
CloudFront
|
v
S3
|
v
๐Ÿ“ฆ Static Content
Students don't need to interact directly with the storage system just to retrieve every object.
CloudFront can provide a delivery layer between users and the origin.

โšก 14. A Faster User Experience

Let's compare the experience.

Without CDN

1
2
3
4
5
6
7
8
9
10
11
12
Student
|
| Request
v
Application Infrastructure
|
v
Content
|
| Long journey back
v
Student

With CDN

1
2
3
4
5
6
7
8
9
10
Student
|
v
Nearby CloudFront Location
|
v
๐Ÿ“ฆ Cached Content
|
v
Student โšก
The exact performance improvement depends on the user's location, network conditions, cache behavior, object size, and many other factors.
But the goal is simple:
Reduce the distance and work required to deliver cacheable content.

๐Ÿง  15. Cloud Architect Challenge

You are now the architect of the college portal.
Which content would you consider for CDN caching?

A

College logo

B

Public CSS file

C

Public JavaScript asset

D

Rahul's private examination result

E

Public college banner
Think carefully.

โœ… A Good Starting Answer

A, B, C and E are typical candidates for caching.
D requires careful handling and should not be treated like ordinary public static content.
The exact decision depends on the application's security and caching design.

๐Ÿ”ฅ 16. Our Architecture Is Becoming a Real Production Architecture

Let's pause for a moment.
Look at what we've built.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
๐Ÿ‘จโ€๐ŸŽ“ Users
|
v
๐ŸŒ CloudFront
/ \
/ \
v v
๐Ÿ“ฆ S3 Content โš–๏ธ Load Balancer
|
v
๐Ÿ“ˆ Auto Scaling
|
+-------------+-------------+
| | |
v v v
EC2-1 EC2-2 EC2-3
| | |
+-------------+-------------+
|
+------+------+
| |
v v
๐Ÿ—„๏ธ RDS Other Services
And each layer has a job.

๐ŸŒ CloudFront

Content delivery and caching.

๐Ÿชฃ S3

Object storage.

โš–๏ธ Load Balancer

Traffic distribution.

๐Ÿ“ˆ Auto Scaling

Dynamic compute capacity.

๐Ÿ–ฅ๏ธ EC2

Application compute.

๐Ÿ—„๏ธ Database

Application data.
This is why cloud architecture is so interesting.
We aren't just learning services.
We're learning how services work together.

๐ŸŽฏ 17. One More Real-World Example

Think about an online shopping website.
Millions of users may request:
1
2
3
4
5
Product Images
CSS
JavaScript
Logos
Videos
These resources can often be cached and delivered through a CDN.
But a request like:
1
"Show me MY current shopping cart."
is dynamic and user-specific.
That requires much more careful handling.
So a modern application might look conceptually like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Users
|
v
๐ŸŒ CDN
/ \
/ \
v v
Static Content Dynamic Requests
| |
v v
S3 Load Balancer
|
v
Application
|
v
Database
The same architectural idea applies to our college portal.

๐Ÿงช 18. Final Mission Challenge

The college has three types of requests.

Request 1

1
GET /college-logo.png
Thousands of students request the same image.
What would you consider?
โžก๏ธ CDN caching.

Request 2

1
GET /my-exam-result
The result belongs to a specific student.
Should we treat it like a public image?
โžก๏ธ No. It requires careful authentication, authorization, and caching behavior.

Request 3

1
POST /register-for-exam
A student submits an examination registration.
Should this be blindly served from a CDN cache?
โžก๏ธ No. This is a dynamic operation that needs to reach the application appropriately.
Congratulations! ๐ŸŽ‰
You're now thinking beyond:
โ€œWhich AWS service should I use?โ€
You're asking:
โ€œWhat kind of request is this, and which layer should handle it?โ€
That's a much more important architectural skill.

๐Ÿ† Mission Complete!

Our college portal has now solved another major problem.
Yesterday we asked:
โ€œHow do we handle more users?โ€
We answered:
Auto Scaling.
Today we asked:
โ€œHow do we deliver content faster to users around the world?โ€
We answered:
CDN + caching + Amazon CloudFront.
Our journey now looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Day 10
๐ŸŒ Networking
โ†“
Day 11
๐Ÿ” Security & IAM
โ†“
Day 12
โš–๏ธ Load Balancing
โ†“
Day 13
๐Ÿ“ˆ Auto Scaling
โ†“
Day 14
๐ŸŒ CDN & CloudFront
And our architecture keeps getting stronger.

๐Ÿš€ Coming Up on Day 15/30

โšก Serverless โ€” What If We Don't Want to Manage Servers at All?

Our college portal is now:
โœ… Secure
โœ… Highly available
โœ… Load balanced
โœ… Auto scaling
โœ… Faster for global users
But Rahul has one more question:
โ€œDo we really need EC2 servers for every little task?โ€
Imagine a student uploads a document.
We need to resize an image.
Or send an email.
Or process a registration event.
Do we really need to keep a server running 24/7 just for those occasional tasks?
๐Ÿค”
What if we could simply say:
โ€œRun this code when something happens.โ€
No server management.
No worrying about keeping the application process running.
Just code that runs when needed.
That's where our next mission begins.

โ˜๏ธ Day 15: Serverless Computing โ€” Run Code Without Managing Servers

The cloud journey continuesโ€ฆ
Build it. Secure it. Scale it. Accelerate it. Automate it.
#CloudComputing #AWS #CloudArchitecture #AmazonCloudFront #CDN #AWSCloud #Caching #30DaysOfCloud

Series: Cloud Computing (25 articles)

  1. โ€ฆ
  2. 15
    ๐ŸŒ Day 14/30: CDN & Amazon CloudFront โ€” How Do We Make Cloud Applications Faster? โšก This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article