CDN Cache-Control, S-MaxAge & Stale-While-Revalidate Egress Calculator
Simulate exact Edge Hit Ratio (%), origin request offload, monthly egress bandwidth savings (GB/TB), and TTFB latency improvements across Cloudflare, AWS CloudFront, Fastly, and GCP. Configure s-maxage, stale-while-revalidate, and immutable directives to slash cloud bills and prevent origin stampedes.
Cache-Control: public, max-age=3600, s-maxage=86400, stale-while-revalidate=600
Technical Breakdown: Direct Origin vs CDN Edge Caching
| Infrastructure Metric | Without CDN Cache | With Cache-Control | Net Optimization |
|---|---|---|---|
| Origin Server Requests | -- | -- | -- |
| Egress Data Transferred | -- | -- | -- |
| Monthly Egress Cloud Cost | -- | -- | -- |
| P95 TTFB Response Latency | 380 ms (P95) | -- | -- |
Engineering Architecture FAQ
What is the difference between max-age and s-maxage?
max-age specifies the maximum time (in seconds) that a client browser is allowed to cache a resource. s-maxage (shared max-age) overrides max-age exclusively for public shared caches (like Cloudflare, CloudFront, or Fastly). This allows you to cache a page on the CDN for 24 hours (s-maxage=86400) while telling client browsers to revalidate every hour (max-age=3600).
How does stale-while-revalidate prevent the 'Thundering Herd' problem?
When a cached resource expires under high traffic, hundreds of concurrent users would normally miss the cache simultaneously, hitting the origin database all at once (cache stampede). stale-while-revalidate instructs the CDN to immediately serve the expired (stale) copy in milliseconds while launching a single asynchronous background request to refresh the origin.
Why do AWS and GCP charge so much for egress compared to Cloudflare?
Major hyperscalers (AWS, Azure, GCP) treat outbound internet data transfer as a high-margin revenue stream, charging between $0.08 and $0.09 per GB. Cloudflare, as co-founder of the Bandwidth Alliance, peers directly with transit networks and waives egress fees between member clouds, reducing data transfer costs to virtually zero.