Create an image CDN fallback policy: error budgets, alt sources, and monitoring.
- User
Create an image CDN fallback policy: error budgets, alt sources, and monitoring.
Assistant
Create an image CDN fallback policy: error budgets, alt sources, and monitoring.
The user wants a policy document or guidelines for handling image CDN fallbacks. The key components requested are:
Target Audience: Engineering teams, DevOps, SREs, and Frontend Developers. Tone: Professional, technical, prescriptive, and actionable.
Structure of the Policy Document:
Drafting Content - Section by Section:
1. Objective: Ensure high availability of visual assets. A broken image ruins trust.
2. Error Budgets:
3. Fallback Strategy (Alt Sources):
<img> tag onerror handler. This is crucial.4. Monitoring:
onerror events in the browser.5. Incident Response:
Refining and Polishing:
Self-Correction during drafting:
Final Structure:
Let's generate the response based on this structure. This policy document outlines a comprehensive strategy for ensuring high availability for image assets. It addresses how to measure reliability (Error Budgets), where to serve images if the primary provider fails (Alt Sources), and how to detect failures (Monitoring).
Version: 1.0 Scope: All web properties serving dynamic or static image assets. Objective: Maintain >99.9% availability for image assets and ensure graceful degradation during outages to preserve User Experience (UX) and Core Web Vitals (CWV).
An Error Budget defines the maximum amount of allowable downtime or failed requests before strict reliability measures are triggered.
200 OK or 304 Not Modified response.| Budget Status | Definition | Action Required |
|---|---|---|
| Healthy | < 10% of monthly budget consumed. | Business as usual. |
| Caution | 10% - 50% of budget consumed. | Code Freeze: No non-critical deployments to Image Infrastructure. Review recent changes. |
| Critical | > 50% of budget consumed. | Emergency Mode: All engineering focus shifts to reliability. Automatic failover is enabled permanently. |
| Exhausted | 100% of budget consumed. | Post-Mortem Required: Reliability takes absolute precedence over new features. |
When the primary CDN fails, the system must automatically switch to an alternative source without requiring a full page reload by the user.
We utilize a "Waterfall" approach to sourcing images:
https://cdn.primary.com/assets/img.jpghttps://storage.secondary.com/assets/img.jpghttps://www.website.com/static/img.jpgNote: Server-side (Edge) logic is preferred, but client-side acts as a safety net.
Method 1: HTML5 <picture> tag (Preferred for static content)
<picture>
<!-- Attempt Tier 2 if Tier 1 type fails (browser support dependent) -->
<source srcset="https://storage.secondary.com/img.webp" type="image/webp">
<!-- Fallback to Tier 1 -->
<img src="https://cdn.primary.com/img.jpg" alt="Description">
</picture>
Method 2: JavaScript Error Handling (Required for dynamic content)
const image = new Image();
image.src = 'https://cdn.primary.com/asset.jpg';
image.onerror = () => {
console.warn('Primary CDN failed. Switching to Secondary Origin.');
// Replace domain part of the URL
image.src = 'https://storage.secondary.com/asset.jpg';
// Optional: Track the failure
trackError('cdn_fallback_triggered');
};
We cannot fix what we cannot see. Monitoring must happen at both the infrastructure level and the user level.
healthcheck.jpg) from the Primary CDN.Content-Type: image/jpeg).img_error_rate.onerror events on the window or specific image tags.status_code (e.g., 404, 502, 503) and the region of the user.cdn.primary.com traffic to storage.secondary.com.