ESC
Type to search guides, tutorials, and reference documentation.
Verified by Garnet Grid

CDN Architecture & Edge Caching

Optimize content delivery with CDNs. Covers cache strategies, edge computing, CDN selection, cache invalidation, origin shielding, and measuring CDN performance.

A CDN (Content Delivery Network) puts your content physically closer to users. Instead of every request traveling from Tokyo to your us-east-1 origin server, the CDN serves cached content from a Tokyo edge location. Latency drops from ~200ms to ~20ms. For static assets, a CDN is the single highest-impact performance optimization you can make.


CDN Architecture

User (Tokyo)                    User (London)
     │                               │
     ▼                               ▼
┌─────────────┐               ┌─────────────┐
│ Edge Tokyo  │               │ Edge London  │
│ (cached)    │               │ (cached)     │
└──────┬──────┘               └──────┬──────┘
       │ Cache MISS                   │ Cache MISS
       ▼                              ▼
┌──────────────────────────────────────────┐
│           Origin Shield (us-east-1)       │
│   (single point of origin fetch)          │
└──────────────────┬───────────────────────┘
                   │ Cache MISS

          ┌─────────────────┐
          │  Origin Server  │
          │  (your app)     │
          └─────────────────┘

Cache Strategy

Content TypeTTLCache-Control Header
Static assets (JS, CSS, images)1 yearpublic, max-age=31536000, immutable
Fonts1 yearpublic, max-age=31536000, immutable
HTML pages0 (revalidate)public, max-age=0, must-revalidate
API responses (public)60-300 secondspublic, max-age=60, s-maxage=300
API responses (private)0private, no-store
User-specific contentNever cache at CDNprivate, no-cache

CDN Selection

ProviderStrengthNetwork SizeBest For
CloudFlareDDoS protection, Workers310+ citiesFull-stack CDN + security
AWS CloudFrontAWS integration, Lambda@Edge450+ PoPsAWS-native applications
FastlyReal-time purging, VCL control90+ PoPsAPI caching, instant purge
AkamaiEnterprise, massive network4,100+ PoPsLarge enterprise, media
Vercel EdgeNext.js integration, serverlessGlobalNext.js applications

Cache Invalidation

StrategySpeedRiskUse Case
TTL expiryAutomaticStale until TTLStatic assets with content hashing
Purge by URLInstantNoneSpecific page update
Purge by tag/keyInstantNoneCategory of content update
Purge everythingInstantOrigin overloadEmergency, major update
Stale-while-revalidateBackgroundServes stale brieflyBalance freshness + speed
Cache-Control: public, max-age=60, stale-while-revalidate=300

Timeline:
0-60s:    Serve from cache (fresh)
60-360s:  Serve stale, fetch fresh in background
360s+:    Cache expired, wait for origin

Anti-Patterns

Anti-PatternProblemFix
No cache headersCDN can’t cache, every request hits originSet Cache-Control on every response
Short TTL on static assetsUnnecessary origin trafficContent hashing + 1-year TTL
Caching user-specific pagesUser A sees User B’s dataCache-Control: private for user content
No origin shieldEvery edge PoP hits origin on cache missEnable origin shield (single PoP between edges and origin)
Cache everything mentalityStale data served to usersCache static, revalidate dynamic

Checklist

  • CDN selected based on needs (security, integrations, edge compute)
  • Cache-Control headers on every response
  • Static assets: content-hashed filenames + 1-year TTL
  • HTML: max-age=0, must-revalidate (or short TTL)
  • API responses: cache public data, no-store for private
  • Origin shield enabled to reduce origin load
  • Cache invalidation: purge by URL/tag for content updates
  • Monitoring: cache hit ratio (target > 90%), origin traffic

:::note[Source] This guide is derived from operational intelligence at Garnet Grid Consulting. For CDN architecture consulting, visit garnetgrid.com. :::

Jakub Dimitri Rezayev
Jakub Dimitri Rezayev
Founder & Chief Architect • Garnet Grid Consulting

Jakub holds an M.S. in Customer Intelligence & Analytics and a B.S. in Finance & Computer Science from Pace University. With deep expertise spanning D365 F&O, Azure, Power BI, and AI/ML systems, he architects enterprise solutions that bridge legacy systems and modern technology — and has led multi-million dollar ERP implementations for Fortune 500 supply chains.

View Full Profile →