Skip to main content

06 - Performance Efficiency

Caching strategies, compression, routing optimization, and latency reduction for Azure Front Door

WAF


🎯 Performance Efficiency Principles

PrincipleFront Door Implementation
Optimize for latencyEdge caching, anycast routing, compression
Scale automaticallyGlobal edge network, no capacity planning
Cache strategicallyRight TTL, query string handling, cache key
Reduce payload sizeCompression, minification, image optimization

✅ Performance Checklist

#RecommendationImpact
1Enable caching for static content🔴 High
2Configure appropriate cache TTLs🔴 High
3Enable compression (gzip/brotli)🔴 High
4Use latency-based routing🟡 Medium
5Optimize query string caching🟡 Medium
6Set appropriate origin timeouts🟡 Medium
7Minimize redirects🟢 Low
8Use HTTP/2🟢 Low

⚡ Latency Optimization

How Front Door Reduces Latency

Latency Components

ComponentTypical LatencyOptimization
Client → Edge POP10-50msAnycast routing (automatic)
TLS Handshake20-50msTLS 1.3, session resumption
WAF Processing1-5msTune rules, exclusions
Cache Lookup<1msHigh cache hit ratio
Edge → Origin50-200msCache more, Private Link
Origin ProcessingVariableOptimize application

Latency-Based Routing

resource originGroup 'Microsoft.Cdn/profiles/originGroups@2023-05-01' = {
name: 'og-latency-optimized'
parent: frontDoor
properties: {
loadBalancingSettings: {
sampleSize: 4
successfulSamplesRequired: 3
additionalLatencyInMilliseconds: 50 // Route to origin within 50ms of fastest
}
healthProbeSettings: {
probePath: '/health'
probeProtocol: 'Https'
probeRequestType: 'HEAD'
probeIntervalInSeconds: 30
}
}
}

Latency Sensitivity Settings:

ValueBehaviorUse Case
0msAlways route to fastest originLatency-critical apps
50msRoute to any origin within 50ms of fastestBalanced (recommended)
200ms+Distribute more evenlyLoad distribution priority

💾 Caching Strategies

Cache Hit Ratio Impact

Caching Configuration

resource staticRoute 'Microsoft.Cdn/profiles/afdEndpoints/routes@2023-05-01' = {
name: 'route-static'
parent: endpoint
properties: {
originGroup: { id: originGroup.id }
patternsToMatch: ['/static/*', '/assets/*', '/images/*']
cacheConfiguration: {
// Cache behavior
cacheBehavior: 'OverrideAlways' // Override origin cache headers
cacheDuration: '7.00:00:00' // 7 days

// Query string handling
queryStringCachingBehavior: 'IgnoreQueryString' // Ignore for static

// Compression
compressionSettings: {
isCompressionEnabled: true
contentTypesToCompress: [
'text/html'
'text/css'
'text/javascript'
'application/javascript'
'application/json'
'image/svg+xml'
'application/xml'
]
}
}
}
}

resource apiRoute 'Microsoft.Cdn/profiles/afdEndpoints/routes@2023-05-01' = {
name: 'route-api'
parent: endpoint
properties: {
originGroup: { id: originGroup.id }
patternsToMatch: ['/api/*']
cacheConfiguration: {
cacheBehavior: 'HonorOrigin' // Respect origin Cache-Control
queryStringCachingBehavior: 'UseQueryString' // Include query in cache key
}
}
}

Query String Caching Behaviors

BehaviorCache KeyUse Case
IgnoreQueryString/page.htmlStatic assets (same content regardless of query)
UseQueryString/page.html?v=1.2.3Versioned assets, API responses
IgnoreSpecifiedQueryStringsExclude specified paramsIgnore tracking params like utm_source
IncludeSpecifiedQueryStringsOnly include specified paramsCache only on relevant params

Cache TTL Recommendations

Content TypeTTLCache-Control Header
Static assets (CSS, JS)7-30 daysmax-age=2592000, immutable
Images7-30 daysmax-age=2592000
Fonts30-365 daysmax-age=31536000, immutable
HTML pages1-5 minutesmax-age=300, s-maxage=60
API responses (cacheable)10-60 secondsmax-age=60, s-maxage=10
User-specific contentDon't cacheprivate, no-store

🗜️ Compression

Compression Impact

Enable Compression

compressionSettings: {
isCompressionEnabled: true
contentTypesToCompress: [
// Text-based formats (high compression ratio)
'text/plain'
'text/html'
'text/css'
'text/javascript'
'text/xml'

// Application formats
'application/javascript'
'application/json'
'application/xml'
'application/xhtml+xml'
'application/rss+xml'
'application/atom+xml'

// Other compressible formats
'image/svg+xml'
'image/x-icon'
'font/ttf'
'font/otf'
'application/vnd.ms-fontobject'
]
}

Compression Best Practices

DoDon't
✅ Compress text-based content❌ Compress already-compressed formats (JPEG, PNG, MP4)
✅ Use brotli for modern browsers❌ Compress small files (< 1KB overhead)
✅ Set Vary: Accept-Encoding❌ Compress encrypted content

🔄 Routing Optimization

Path-Based Routing for Performance

// Optimized multi-route configuration
var routes = [
{
name: 'static-assets'
patterns: ['/static/*', '/assets/*', '/_next/static/*']
originGroup: staticOriginGroup
cacheDuration: '30.00:00:00'
queryString: 'IgnoreQueryString'
}
{
name: 'api'
patterns: ['/api/*']
originGroup: apiOriginGroup
cacheDuration: null // Honor origin
queryString: 'UseQueryString'
}
{
name: 'default'
patterns: ['/*']
originGroup: webOriginGroup
cacheDuration: '00:05:00'
queryString: 'UseQueryString'
}
]

Origin Selection Strategy

StrategyConfigurationBest For
Lowest LatencyadditionalLatencyInMilliseconds: 0Real-time apps
BalancedadditionalLatencyInMilliseconds: 50General web apps
Weightedweight: 1000/500Gradual rollout
Priority Failoverpriority: 1/2DR scenarios

📊 Performance Monitoring

Key Performance Metrics

MetricTargetQuery
Cache Hit Ratio> 80%See below
Origin Latency< 200msSee below
Total Latency< 100ms (cached)See below
5XX Error Rate< 0.1%See below

Performance Queries (KQL)

Cache Hit Ratio

AzureDiagnostics
| where Category == "FrontDoorAccessLog"
| where TimeGenerated > ago(24h)
| summarize
Total = count(),
Hits = countif(cacheStatus_s == "HIT"),
Misses = countif(cacheStatus_s == "MISS"),
Other = countif(cacheStatus_s !in ("HIT", "MISS"))
| extend HitRatio = round((Hits * 100.0) / Total, 2)
| project HitRatio, Total, Hits, Misses, Other

Latency Percentiles

AzureDiagnostics
| where Category == "FrontDoorAccessLog"
| where TimeGenerated > ago(1h)
| extend LatencyMs = toint(timeTaken_s) * 1000
| summarize
P50 = percentile(LatencyMs, 50),
P75 = percentile(LatencyMs, 75),
P95 = percentile(LatencyMs, 95),
P99 = percentile(LatencyMs, 99)
by bin(TimeGenerated, 5m)
| render timechart

Slow Requests Analysis

AzureDiagnostics
| where Category == "FrontDoorAccessLog"
| where TimeGenerated > ago(1h)
| extend LatencyMs = toint(timeTaken_s) * 1000
| where LatencyMs > 1000 // Requests > 1 second
| project
TimeGenerated,
requestUri_s,
LatencyMs,
cacheStatus_s,
originName_s,
httpStatusCode_s
| order by LatencyMs desc
| take 100

Cache Miss Analysis

// Identify high-volume cache misses (optimization opportunities)
AzureDiagnostics
| where Category == "FrontDoorAccessLog"
| where cacheStatus_s == "MISS"
| summarize MissCount = count() by requestUri_s
| order by MissCount desc
| take 50

⚙️ Rules Engine for Performance

URL Rewrite (Reduce Origin Load)

resource ruleSet 'Microsoft.Cdn/profiles/ruleSets@2023-05-01' = {
name: 'performance-rules'
parent: frontDoor
}

// Redirect to CDN for known static patterns
resource staticRedirectRule 'Microsoft.Cdn/profiles/ruleSets/rules@2023-05-01' = {
name: 'redirect-static-to-cdn'
parent: ruleSet
properties: {
order: 1
conditions: [
{
name: 'UrlPath'
parameters: {
typeName: 'DeliveryRuleUrlPathMatchConditionParameters'
operator: 'BeginsWith'
matchValues: ['/legacy-static/']
}
}
]
actions: [
{
name: 'UrlRewrite'
parameters: {
typeName: 'DeliveryRuleUrlRewriteActionParameters'
sourcePattern: '/legacy-static/'
destination: '/static/'
preserveUnmatchedPath: true
}
}
]
}
}

Cache Override Rules

// Force cache for specific paths regardless of origin headers
resource forceCacheRule 'Microsoft.Cdn/profiles/ruleSets/rules@2023-05-01' = {
name: 'force-cache-assets'
parent: ruleSet
properties: {
order: 2
conditions: [
{
name: 'UrlFileExtension'
parameters: {
typeName: 'DeliveryRuleUrlFileExtensionMatchConditionParameters'
operator: 'Equal'
matchValues: ['js', 'css', 'woff2', 'woff', 'ttf']
}
}
]
actions: [
{
name: 'CacheExpiration'
parameters: {
typeName: 'DeliveryRuleCacheExpirationActionParameters'
cacheBehavior: 'Override'
cacheType: 'All'
cacheDuration: '30.00:00:00'
}
}
]
}
}

🚀 Performance Optimization Patterns

Pattern 1: Static Asset Optimization

Implementation:

  • Use versioned file names or query strings
  • Set Cache-Control: max-age=2592000, immutable
  • Configure Front Door to IgnoreQueryString or UseQueryString

Pattern 2: API Response Caching

// Short-lived cache for API responses
cacheConfiguration: {
cacheBehavior: 'OverrideIfOriginMissing'
cacheDuration: '00:01:00' // 1 minute
queryStringCachingBehavior: 'UseQueryString'
}

Best Practices:

  • Cache GET requests only
  • Include query params in cache key
  • Use Vary header for different response formats
  • Set short TTL (30-60 seconds)

Pattern 3: Stale-While-Revalidate

Configure origin to return:

Cache-Control: max-age=60, stale-while-revalidate=300

This allows Front Door to:

  1. Serve cached content immediately
  2. Fetch fresh content in background
  3. Update cache for next request

📋 Performance Summary

OptimizationImplementationExpected Impact
Enable cachingRoute-level cache config50-90% latency reduction
CompressionGzip/brotli for text content60-80% bandwidth reduction
Latency routingadditionalLatencyInMilliseconds: 5010-30% latency reduction
Query string optimizationIgnoreQueryString for staticHigher cache hit ratio
Path-based routingSeparate routes by content typeBetter cache efficiency
Rules EngineForce cache headersConsistent caching

🔗 References

ResourceLink
Performance EfficiencyWAF Performance Efficiency
CachingFront Door Caching
CompressionEnable Compression
Rules EngineFront Door Rules Engine

Previous: 05 - Operational Excellence

📖Learn