Introduction When CDN cache keys do not account for request variations (User-Agent, language, cookies), users receive content intended for different clients, causing broken layouts and incorrect content.

Symptoms - Mobile users seeing desktop layout - Desktop users seeing mobile layout - Content in wrong language - Logged-in users seeing anonymous content - A/B test variant shown to wrong users

Common Causes - CDN cache key not including User-Agent header - Vary header not respected by CDN - Cookie values not included in cache key - Accept-Language header ignored - CDN normalizing cache keys too aggressively

Step-by-Step Fix 1. **Check current cache key configuration': ```bash # CloudFront aws cloudfront get-distribution --id E123 \ --query 'Distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues' ```

  1. 1.**Configure cache variation by headers':
  2. 2.```bash
  3. 3.# Forward User-Agent to origin for cache variation
  4. 4.aws cloudfront update-distribution --id E123 --cli-input-json '{
  5. 5."DistributionConfig": {
  6. 6."DefaultCacheBehavior": {
  7. 7."ForwardedValues": {
  8. 8."QueryString": true,
  9. 9."Headers": {"Items": ["User-Agent"], "Quantity": 1}
  10. 10.}
  11. 11.}
  12. 12.}
  13. 13.}'
  14. 14.`

Prevention - Configure cache keys based on content variation needs - Use separate CDN distributions for mobile and desktop - Implement responsive design to reduce content variation - Monitor cache hit ratio per content variant - Test content delivery from different client types