CDN
Content Delivery Network
Caches content on edge servers around the world. Reduces latency. CloudFront, Cloudflare.
Content Delivery Network
Caches content on edge servers around the world. Reduces latency. CloudFront, Cloudflare.
A CDN (Content Delivery Network) is a technology that delivers content from locations close to users through a network of edge servers distributed around the world. It fetches content from the origin server (Origin), caches it on edge servers, and responds from the nearest edge when a user makes a request, dramatically reducing latency (Latency).
The core principles of a CDN are caching (Caching) and geographic distribution. Static content such as images, CSS, JavaScript, and video is stored at the edge for the TTL (Time To Live), so repeated requests do not put load on the origin server. Large CDN providers operate more than 200 PoPs (Point of Presence) worldwide.
Modern CDNs go beyond simple caching and also provide DDoS protection, WAF (Web Application Firewall), image optimization, video streaming, and edge computing features. You can also run code at the edge with services such as Cloudflare Workers and AWS Lambda@Edge.
Major CDN providers include Cloudflare (free plan available, 310+ PoPs worldwide), AWS CloudFront (integrated with AWS services), Akamai (No. 1 in the enterprise market), and Fastly (real-time purge, developer-friendly). In Korea, domestic CDNs such as SK Broadband and KT are also options.
# AWS CloudFront CDK 설정
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
import * as s3 from 'aws-cdk-lib/aws-s3';
// S3 버킷 생성
const bucket = new s3.Bucket(this, 'WebsiteBucket', {
websiteIndexDocument: 'index.html',
});
// CloudFront 배포 생성
const distribution = new cloudfront.Distribution(this, 'CDN', {
defaultBehavior: {
origin: new origins.S3Origin(bucket),
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
compress: true,
},
// 커스텀 캐시 정책
additionalBehaviors: {
'/api/*': {
origin: new origins.HttpOrigin('api.example.com'),
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER,
},
'/static/*': {
origin: new origins.S3Origin(bucket),
cachePolicy: new cloudfront.CachePolicy(this, 'StaticCache', {
maxTtl: Duration.days(365),
defaultTtl: Duration.days(30),
minTtl: Duration.hours(1),
}),
},
},
// 지역 제한 (한국, 일본, 미국만 허용)
geoRestriction: cloudfront.GeoRestriction.allowlist('KR', 'JP', 'US'),
// 커스텀 도메인
domainNames: ['cdn.example.com'],
certificate: myCertificate,
});
"TTFB is 2 seconds, but adding a CDN can bring it down to under 200ms. If we serve static assets through CloudFront and enable automatic WebP conversion for images, bandwidth can also be reduced by about 40%. For a global service, Cloudflare is also worth considering; the free plan is quite decent too."
"I have experience designing CDN cache strategies. For static files, I applied an immutable cache with hashed filenames, and for HTML, I used stale-while-revalidate to get both fast responses and freshness. For cache invalidation, I made changes take effect immediately by changing filenames, and for emergencies I also implemented manual purge with the CloudFront Invalidation API."
"A report just came in that the CSS broke after deployment. It looks like a CDN cache problem. We didn't add a hash to the filename at build time, so browsers are caching the old CSS. For now, run an Invalidation on CloudFront with the /*.css pattern, and the fundamental fix is to apply hashed filenames in CI/CD."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
If responses containing per-user personal information or authentication tokens are cached on the CDN, they will be exposed to other users. For API responses and dynamic content, explicitly specify Cache-Control: private or no-store.
If you set max-age=31536000 (1 year) but the filenames have no hash, users will keep receiving old files even after an update. CloudFront Invalidation incurs costs (1,000 requests per month free) and takes time to propagate.
Set static assets to an immutable cache with content-hash filenames (main.a1b2c3d4.js), and HTML to no-cache or a short TTL. Set the Cache-Control response header accurately on the origin server, and track the cache hit ratio (CHR) with CDN monitoring.