

# Advanced optimization techniques for CDN and MediaTailor integrations
<a name="cdn-advanced-optimization"></a>

After implementing basic caching and routing optimizations, consider these advanced techniques to further enhance performance:

## Origin Shield implementation
<a name="origin-shield-optimization"></a>

Origin Shield adds a caching layer between CDN edge locations and your origin server, reducing origin load and improving performance:
+ Enable Origin Shield for high-traffic content and live streaming
+ Choose Origin Shield locations close to your MediaTailor regions
+ Monitor Origin Shield cache hit ratios and adjust as needed
+ Consider multiple Origin Shield locations for global deployments

## Content compression optimization
<a name="compression-optimization"></a>

Optimize content compression to reduce bandwidth and improve delivery speed:
+ Enable gzip compression for manifest files
+ Configure Accept-Encoding header forwarding for MediaTailor manifest compression
+ Use Brotli compression where supported for additional bandwidth savings
+ Avoid compressing already-compressed video segments

## Regional optimization strategies
<a name="regional-optimization"></a>

Optimize performance for global audiences through regional strategies:
+ Deploy MediaTailor configurations in multiple regions for global audiences
+ Use geo-routing to direct viewers to the nearest MediaTailor region
+ Configure regional failover for high availability
+ Monitor regional performance metrics separately

# Architecture considerations for CDN and MediaTailor integrations
<a name="cdn-architecture-considerations"></a>

Position your content delivery network (CDN) correctly in your architecture to ensure optimal performance and reliability with AWS Elemental MediaTailor. The recommended architecture places the CDN between viewers and MediaTailor, not between MediaTailor and your origin.

For detailed architecture diagrams and workflow explanations, see the following topics.
+ [Ad insertion with CDN](ssai-cdn-workflow.md) for ad insertion architecture diagrams and detailed workflow
+ [Understand CDN architecture](channel-assembly-cdn-architecture.md) for channel assembly architecture diagrams and workflow

Position your CDN correctly in your architecture:

1. Place your CDN between players and MediaTailor (not between MediaTailor and your origin).

   This architecture allows your CDN to cache ad segments and content segments. At the same time, MediaTailor can generate personalized manifests for each viewer.

1. Create separate cache behaviors for different request types:
   + Manifest requests (no caching)
   + Content segments (longer TTL)
   + Ad segments (longer TTL)

1. Configure proper error handling:
   + Set up negative caching (temporarily storing error responses) to avoid overwhelming your origin with repeated requests during service disruptions. Negative caching means the CDN will temporarily store error responses (like 404 or 500 errors) to prevent repeated requests for content that doesn't exist or is temporarily unavailable.
   + Configure appropriate error response codes and retry behavior

1. Implement intermediate caching (origin shield):

   Origin shield is a feature that creates an additional caching layer between CDN edge locations and your origin server. This reduces the number of redundant requests that reach your origin server.
   + Configure an intermediate caching layer between edge locations and your origin
   + Reduce the number of redundant requests to your origin during cache misses
   + Improve cache hit ratios across your CDN infrastructure

# Advanced CDN features for MediaTailor
<a name="advanced-cdn-features"></a>

After implementing basic content delivery network (CDN) configuration, explore these advanced features to further enhance your AWS Elemental MediaTailor streaming platform's performance and reliability.

Media Quality-Aware Routing (MQAR)  
MQAR is an Amazon CloudFront feature that automatically selects the highest quality content source based on real-time network performance metrics. Instead of using a fixed origin server, MQAR dynamically routes requests to the best-performing origin based on factors like latency and throughput. This helps ensure viewers receive the highest possible quality stream even during network fluctuations.  
If you use Amazon CloudFront, implement MQAR to automatically select the highest quality content source based on real-time metrics. For details, see [CloudFront integration](cloudfront-specific-recommendations.md) in the CloudFront integration section.

Manifest filtering  
Manifest filtering allows you to customize which renditions (different quality versions of the same content) are included in the manifests that MediaTailor delivers to viewers. Filtering helps optimize bandwidth usage by removing renditions that aren't appropriate for certain devices or network conditions. For example, you might remove 4K renditions for mobile devices or low-bandwidth connections.  
For detailed information about implementing manifest filtering with AWS Elemental MediaPackage, see [MediaPackage CDN integration](mediapackage-integration.md).

Multi-CDN strategy  
A multi-CDN strategy uses multiple CDN providers simultaneously to improve reliability and performance. If one CDN experiences issues, traffic can automatically shift to another provider. This approach is particularly valuable for high-profile live events where reliability is critical.  
For information about implementing a multi-CDN strategy with MediaTailor, see [Plan CDN integration](planning-cdn-integration.md).