
๐ 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)
- โฆ
- 15๐ Day 14/30: CDN & Amazon CloudFront โ How Do We Make Cloud Applications Faster? โก This article
๐ 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-3More 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 StudentNow 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 Serverversus:
1
2
3
4
5
6
7
8
With CDN
User
|
v
Nearby CDN Location
|
+---- Cached ContentThe 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-3After 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-2Now 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 LogoCloudFront 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 LogoThe 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
StudentThe 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 / OriginA 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.pdfThousands 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 FilesRequires careful handling
1
2
3
4
5
Student Exam Result
Personal Profile
Payment Information
Private Dashboard
Authentication ResponsesThe 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-3This 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
DatabaseNow 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 / AssetsThis 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.pnginside 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 ContentStudents 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
StudentWith 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 ServicesAnd 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
VideosThese 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
DatabaseThe 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.pngThousands of students request the same image.
What would you consider?
โก๏ธ CDN caching.
Request 2
1
GET /my-exam-resultThe 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-examA 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 & CloudFrontAnd 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)
- โฆ
- 15๐ Day 14/30: CDN & Amazon CloudFront โ How Do We Make Cloud Applications Faster? โก This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article