How does Amazon CloudFront speed up a website?
CloudFront is a content delivery network that caches copies of your content at edge locations close to users. A request is served from the nearest edge if cached; otherwise it fetches from your origin, such as S3 or an ALB, and keeps a copy.
Explain it simply
Think of a newspaper printed in Delhi. Rather than every reader in Chennai waiting for a courier from Delhi, local agents in each city keep a stack of today's copies. Readers pick it up nearby. CloudFront edge locations are those local agents.
Example
User in Pune requests /images/logo.png
1. DNS sends the user to the nearest CloudFront edge
2. Edge has it cached? -> cache HIT, served in milliseconds
3. Not cached? -> cache MISS, fetch from origin (S3 / ALB)
4. Edge stores it for the TTL and returns it
5. Next user nearby gets a cache hit
Useful settings
TTL how long objects stay cached
Invalidation remove cached objects early: /images/*
OAC Origin Access Control: only CloudFront can read a private S3 bucket
HTTPS free certificates from AWS Certificate ManagerBenefits: lower latency, less load on the origin, and some protection against traffic spikes. CloudFront also works for dynamic content and video streaming, and it integrates with AWS WAF and AWS Shield.
To update a file immediately, either use a versioned file name such as app.v2.js or invalidate the path.
What to say in the interview
"CloudFront caches content at edge locations near users and fetches from the origin only on a miss, so pages load faster and the origin is less loaded. I use TTLs, versioned file names or invalidations for updates, and Origin Access Control to keep S3 private."
Common mistakes
- Making the S3 bucket public instead of restricting it to CloudFront.