Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

6.3.3. CloudFront Caching and Troubleshooting

šŸ’” First Principle: A CloudFront cache miss is equivalent to routing the request all the way to the origin — which defeats the purpose of having a CDN. Troubleshooting CloudFront is fundamentally about two questions: why is the cache hit rate lower than expected, and why are users seeing incorrect or stale content?

Cache Hit Ratio Optimization:

Low cache hit ratios (CloudFront CacheHitRate metric below ~85% for static content) indicate something is making cache keys unnecessarily unique:

CauseFix
Query strings vary per request (session IDs in URL)Configure cache policy to ignore or remove dynamic query strings
Cookies forwarded to originConfigure cache policy to forward only necessary cookies
Too many Vary header valuesControl which headers vary the cache key
TTL too lowIncrease default TTL in cache policy
Content changes frequentlyUse versioned file names instead of invalidations
CloudFront X-Cache Header:

Responses from CloudFront include the X-Cache header:

  • Hit from cloudfront — served from edge cache
  • Miss from cloudfront — cache miss, fetched from origin
  • RefreshHit from cloudfront — expired cache entry refreshed
  • Error from cloudfront — origin returned an error
Common CloudFront Error Scenarios:
ErrorCauseFix
502CloudFront couldn't connect to originCheck origin health, security groups, ALB listener
503Origin returned 503Check origin capacity
504Origin didn't respond within timeoutIncrease CloudFront origin timeout; optimize origin response time
Stale contentTTL not expiredCreate invalidation; use versioned file names going forward
Viewer gets wrong contentCache key collisionEnsure cache key includes all varying dimensions (headers, cookies, query strings)

āš ļø Exam Trap: CloudFront invalidations are not instant — they propagate to all edge locations and typically complete in a few minutes, but not immediately. During the propagation window, some edge locations may still serve stale content. For time-critical updates, the better practice is versioned file names — app-v2.js instead of overwriting app.js. Viewers always get the latest version because the file name changes, and old versions expire from cache naturally.

Reflection Question: An e-commerce site deployed a CloudFront distribution for their product catalog (images and JSON). The cache hit rate is 12% — much lower than expected. Investigation shows that each request URL includes a unique session ID as a query string (?session=abc123). What configuration change fixes the low cache hit rate?

Alvin Varughese
Written byAlvin Varughese
Founder•15 professional certifications