

# Performance optimization guide for CDN and MediaTailor integrations
<a name="cdn-optimization"></a>

AWS Elemental MediaTailor performance can be maximized through systematic content delivery network (CDN) optimization. Whether you're implementing server-side ad insertion (SSAI), channel assembly, or combined workflows, the optimization principles and performance targets remain consistent. This guide provides comprehensive optimization techniques and benchmarks that apply across all MediaTailor implementations.

For advanced routing optimization using dynamic variables and configuration aliases, see [MediaTailor dynamic ad variables for ADS requests](variables.md). For query parameter optimization strategies, see [MediaTailor manifest query parameters](manifest-query-parameters.md).

**Optimization workflow overview:**

1. **Configure caching** - Set appropriate TTL values and cache behaviors

1. **Optimize routing** - Configure request routing and origin policies

1. **Measure performance** - Track against established benchmarks

1. **Apply advanced techniques** - Implement additional optimization features

**Topics**
+ [Caching optimization](cdn-optimize-caching.md)
+ [Request routing optimization](cdn-optimize-routing.md)
+ [Performance benchmarks](cdn-performance-benchmarks.md)
+ [Advanced optimization](cdn-advanced-optimization.md)

# Caching optimization for CDN and MediaTailor integrations
<a name="cdn-optimize-caching"></a>

AWS Elemental MediaTailor caching requirements vary by workflow type and content format. Proper caching configuration is critical for optimal performance, cost efficiency, and viewer experience. The following sections provide detailed caching guidance for different MediaTailor implementations.

## Server-side ad insertion (SSAI) caching
<a name="ssai-caching-optimization"></a>

For server-side ad insertion workflows, personalized manifests cannot be cached, but content and ad segments should be cached aggressively:


**SSAI CDN caching settings**  

| Content type | TTL | Path pattern | Cache key elements | 
| --- | --- | --- | --- | 
| Multivariant playlists | 0 seconds | /v1/master/\$1 | URL path \$1 all query parameters | 
| Media playlists | 0 seconds | /v1/manifest/\$1 | URL path \$1 all query parameters | 
| DASH MPDs | 0 seconds | /v1/dash/\$1 | URL path \$1 all query parameters | 
| Content segments | 24\$1 hours | Content-specific paths | URL path only | 
| Ad segments | 24\$1 hours | /v1/segment/\$1 | URL path only | 
+ Set TTL of 0 seconds for personalized manifests to ensure viewers receive up-to-date ad content
+ Configure longer TTL values for content and ad segments to maximize cache efficiency
+ Set up cache behaviors that include personalization parameters in the cache key if you support targeted advertising
+ Implement request collapsing at the CDN level to efficiently handle concurrent requests

### Recommended TTL configuration settings
<a name="ssai-ttl-configuration"></a>

For optimal SSAI performance, configure your CDN cache policies with these specific TTL settings:


**SSAI TTL configuration settings**  

| Content type | TTL setting | Recommended value | 
| --- | --- | --- | 
| Ad segments | Min TTL | 1 second | 
| Ad segments | Max TTL | 86400 seconds (24 hours) | 
| Ad segments | Default TTL | 86400 seconds (24 hours) | 
| Content segments | Min TTL | 1 second | 
| Content segments | Max TTL | 86400 seconds (24 hours) | 
| Content segments | Default TTL | 86400 seconds (24 hours) | 

These settings ensure:
+ **Min TTL of 1 second**: Allows for rapid cache invalidation when needed while preventing excessive origin requests
+ **Max TTL of 24 hours**: Balances cache efficiency with content freshness requirements
+ **Default TTL of 24 hours**: Provides optimal caching for segments that don't have explicit cache-control headers

## Server-guided ad insertion (SGAI) caching
<a name="sgai-caching-optimization"></a>

Server-guided ad insertion (SGAI) enables efficient CDN caching through cacheable media manifests that use predictable URL patterns. This section focuses on CDN-specific configuration requirements for optimal SGAI performance.

### CDN caching configuration for SGAI
<a name="sgai-caching-configuration"></a>

Configure your CDN with these SGAI-specific caching behaviors:


**SGAI CDN caching settings**  

| Content type | TTL | Path pattern | Cache key elements | 
| --- | --- | --- | --- | 
| SGAI multivariant playlists (do not cache) | 0 seconds (do not cache) | /v1/master/\$1 | URL path \$1 selected query parameters | 
| SGAI media playlists | 1-4 seconds (half segment length) | /v1/i-media/\$1 | URL path \$1 selected query parameters | 
| Asset list responses (do not cache) | 0 seconds (do not cache) | /v1/interstitials/\$1 | URL path \$1 all query parameters | 
| Ad segments | 24\$1 hours | Ad-specific paths | URL path only | 

### Cache behavior configuration
<a name="sgai-cache-behavior-setup"></a>

Set up dedicated cache behaviors for SGAI content:
+ **SGAI manifest behavior** - Create a cache behavior for `/v1/i-media/*` paths with 1-4 second TTL
+ **Asset list behavior** - Create a cache behavior for `/v1/interstitials/*` paths with 0 second TTL
+ **Query parameter handling** - Include only essential targeting parameters in cache keys to maximize cache efficiency
+ **Origin request headers** - Forward necessary headers for ad targeting while maintaining cacheability

## Channel assembly caching
<a name="channel-assembly-caching-optimization"></a>

For channel assembly workflows, manifests can be cached for short periods, while segments should be cached aggressively:


**Channel assembly CDN caching settings**  

| Content type | VOD TTL | Live TTL | Path pattern | Cache key elements | 
| --- | --- | --- | --- | --- | 
| Multivariant playlists | 5-30 minutes | 5-10 seconds | Channel-specific paths | URL path \$1 all query parameters | 
| Media playlists | 5-30 minutes | 2-5 seconds | Channel-specific paths | URL path \$1 all query parameters | 
| DASH MPDs | 5-30 minutes | 5-10 seconds | Channel-specific paths | URL path \$1 all query parameters | 
| Content segments | 24\$1 hours | 5-15 minutes | Content-specific paths | URL path only | 
| Ad segments | 24\$1 hours | 24\$1 hours | Ad-specific paths | URL path only | 
+ Set short TTL values for manifests to ensure viewers receive up-to-date programming
+ Configure longer TTL values for content segments to maximize cache efficiency
+ Set up cache behaviors that include time-shift parameters in the cache key if you support time-shifted viewing
+ Include query parameters in the cache key to properly handle time-shifted viewing requests

For detailed TTL configuration settings and best practices, see [Caching optimization for CDN and MediaTailor integrations](#cdn-optimize-caching).

## Combined SSAI and channel assembly caching
<a name="combined-workflow-caching"></a>

When implementing both channel assembly and SSAI, ensure your caching strategy is consistent for both services to avoid conflicts and optimize performance:


**Combined workflow caching settings comparison**  

| Content type | Channel assembly | SSAI | Combined recommendation | 
| --- | --- | --- | --- | 
| VOD manifests | 5-30 minutes | 0 seconds | (use a separate config) | 
| Live manifests | 2-10 seconds | 0 seconds | (use a separate config) | 
| SGAI VOD manifests | 5-30 minutes | 5-30 minutes | 5-30 minutes (cacheable manifests) | 
| SGAI Live manifests | 2-4 seconds | 2-4 seconds | 2-4 seconds (cacheable manifests) | 
| Content segments | 24\$1 hours | 24\$1 hours | 24\$1 hours (consistent) | 
| Ad segments | 24\$1 hours | 24\$1 hours | 24\$1 hours (consistent) | 

This configuration maximizes cache efficiency while ensuring viewers receive up-to-date manifests for personalized ad insertion.

# Request routing optimization for CDN and MediaTailor integrations
<a name="cdn-optimize-routing"></a>

Implement these routing optimizations for all AWS Elemental MediaTailor CDN integrations:
+ Create separate cache behaviors for manifest and segment requests
+ Configure origin request policies to control header forwarding
+ Set up proper error handling and failover mechanisms
+ Implement origin shields if available in your CDN to reduce origin load
+ Implement request collapsing at the CDN level to efficiently handle concurrent requests

# Performance benchmarks for CDN and MediaTailor integrations
<a name="cdn-performance-benchmarks"></a>

When optimizing your AWS Elemental MediaTailor CDN integration, aim for these performance benchmarks. These targets apply to all MediaTailor implementations including SSAI, channel assembly, and combined workflows:

Cache Hit Ratio Targets  
Content segments: greater than 95% cache hit ratio  
Ad segments: greater than 90% cache hit ratio  
Manifests: Not applicable for SSAI (should not be cached for personalized ad insertion); 85%\$1 for channel assembly

Latency Benchmarks  
Manifest request latency: less than 100ms (P95)  
Content segment delivery: less than 50ms (P95)  
Ad segment delivery: less than 75ms (P95)  
End-to-end startup time: less than 2 seconds

Origin Load Metrics  
Origin requests per viewer: less than 0.1 requests per minute per viewer  
Origin bandwidth per viewer: less than 5% of total viewer bandwidth

Error Rate Targets  
Manifest errors: less than 0.1%  
Segment errors: less than 0.01%  
Player-reported rebuffering: less than 1%

Scalability Benchmarks  
Support for 10 times the normal traffic during peak events without degradation  
Ability to handle greater than 1000 requests per second per channel

Use Amazon CloudWatch metrics to track these performance indicators. For detailed monitoring instructions, see [Set up monitoring tools](cdn-monitoring.md#cdn-monitor-tools-setup).

# 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).