CDN Caching: CloudFront Distribution Strategy

This article explains how we use CloudFront CDN to cache content and improve global performance.

The Problem: Global Latency

Users access our website from around the world:

  • India: 50ms latency

  • USA: 200ms latency

  • Europe: 250ms latency

  • Asia: 150ms latency

Serving all traffic from India causes slow page loads for international users.

The Solution: CloudFront CDN

CloudFront: AWS Content Delivery Network

Edge locations: 400+ locations worldwide

Benefit: Content served from nearest location

What Gets Cached

Static Assets (Long TTL)

Content: Images, CSS, JavaScript, fonts

TTL: 1 year

Path: /s/*

Benefit: Rarely changes, cache aggressively

Product Pages (Medium TTL)

Content: Product specifications, images

TTL: 1 hour

Path: /p/*

Benefit: Balance freshness and performance

Query Pages (Short TTL)

Content: Search results, filtered views

TTL: 5 minutes

Path: /q/*

Benefit: Frequent updates, short cache

Articles (Long TTL)

Content: Technical documentation

TTL: 24 hours

Path: /a/*

Benefit: Rarely changes

What's NOT Cached

Dynamic content:

  • Search results (/q/?q=<query>)

  • User-specific content (cart, account)

  • API endpoints (/api/*)

Reason: Must be fresh, user-specific

Cache Behavior

Cache Key

CloudFront uses URL as cache key:

Same URL: Served from cache

Different URL: New cache entry

Query parameters: Included in key (except tracking params)

Cache Headers

Origin server sets cache headers:

Cache-Control: public, max-age=3600

public: Can be cached by CDN

max-age: Cache duration in seconds

Cache Invalidation

Manual: Create invalidation request

Automatic: Wait for TTL expiry

Cost: First 1,000 paths free per month

See: CACHE_INVALIDATION_RULE.md for policy

Origin Protection

CDN protects origin server:

Traffic absorption: CDN handles traffic spikes

DDoS mitigation: Filters malicious traffic

Rate limiting: Prevents origin overload

Benefit: Origin stays responsive

SSL/TLS

Certificate: AWS Certificate Manager

Protocol: TLS 1.2+

Benefit: Encrypted traffic, free certificate

Compression

Gzip: Enabled for text content

Brotli: Enabled for modern browsers

Benefit: Faster downloads, lower bandwidth

Geographic Restrictions

None: Available worldwide

Benefit: Global reach

Monitoring

Metrics:

  • Cache hit rate

  • Origin requests

  • Error rate

  • Latency per region

CloudWatch: AWS monitoring service

Cost Optimization

Cache hit rate: Higher = lower costs

Origin requests: Fewer = lower costs

Data transfer: Cached = cheaper

Benefit: CDN reduces infrastructure costs

References

AWS Services

Related Articles

Summary

CloudFront CDN improves global performance:

Cached content:

  • ✅ Static assets (1 year TTL)

  • ✅ Product pages (1 hour TTL)

  • ✅ Query pages (5 minutes TTL)

  • ✅ Articles (24 hours TTL)

Not cached:

  • ✅ Dynamic search

  • ✅ User-specific content

  • ✅ API endpoints

Benefits:

  • ✅ Lower latency (edge locations)

  • ✅ Origin protection (traffic absorption)

  • ✅ DDoS mitigation

  • ✅ Cost reduction (fewer origin requests)

Features:

  • ✅ SSL/TLS encryption

  • ✅ Gzip/Brotli compression

  • ✅ Global availability

This CDN strategy balances performance, freshness, and cost.


← Back to Documentation Index