Tag: Observability

Metrics, logs, traces, and operational diagnostics for image pipelines.

  • What should image pipeline observability include?

    What should image pipeline observability include?

    Short answer: Observe each stage separately: upload, source fetch, transformation, derivative storage, CDN cache, browser selection, and page rendering. Use stable asset and request identifiers, bounded labels, sampled detail, and alerts tied to user impact rather than raw request volume.

    An image that looks slow in a browser may be waiting on the HTML, fetched from a remote origin, encoded for the first time, missed at the edge, oversized for its slot, or delayed by rendering. A single endpoint latency metric cannot distinguish those causes.

    What should ingestion expose?

    Track upload attempts, accepted and rejected bytes, validation duration, processing duration, ready rate, failure reason, retry count, and age of the oldest unfinished asset. Record asset ID and upload intent ID so retries can be connected without creating duplicates.

    Monitor dimensions, formats, and pixel counts of accepted sources. A sudden change may signal a new content workflow that exceeds assumptions. Treat rejection categories as product feedback as well as security signals.

    The upload pipeline guide defines useful lifecycle states. Dashboards should use the same state vocabulary so operators and application developers discuss one model.

    What should source retrieval expose?

    For origin-pull systems, record normalized origin name, status, DNS and connection timing when available, time to first byte, response bytes, redirect count, timeout type, and policy rejection. Avoid raw remote URLs if they contain credentials or uncontrolled high-cardinality query strings.

    Separate origin failures from transformation failures. A processor cannot fix a slow or unauthorized source. Track the percentage of transformations that required a remote fetch versus a managed original.

    Security rejects belong here too. Denied private addresses, disallowed hosts, and invalid redirects should feed alerts described in the remote origin protection guide.

    What should transformation expose?

    Measure cold transformation rate, queue delay, processing duration, output dimensions, output format, encoded bytes, failure reason, and resource-limit rejection. Aggregate by named preset and bounded dimension bucket rather than full raw transformation strings.

    Track unique normalized variants per asset and new variants per minute. These reveal unbounded dimensions or abuse. A sharp increase can precede storage and cost problems even when requests still succeed.

    If automatic format or quality is used, record the resulting format and policy tier. Without output facts, an unexpected large response becomes hard to explain.

    What should cache and delivery expose?

    At each cache layer, capture hit, miss, stale, revalidated, or bypass status; age; response time; response bytes; content type; and region. Distinguish derivative-cache reuse from CDN edge hits if the platform makes both visible.

    Monitor cache hit ratio alongside request distribution. A healthy global ratio can hide one region, preset, or route with persistent misses. Track purge requests and completion separately from normal delivery.

    The cache key design guide supplies the fields needed to interpret fragmentation. Do not use full signed URLs as metric labels. Extract a stable preset, version, and status while placing detailed URLs only in access-controlled sampled logs.

    What should the browser and page expose?

    Collect selected candidate, rendered dimensions, intrinsic dimensions, transferred bytes, image timing, LCP attribution, and layout shift involvement for a sample of page views. Segment by page template, component, device class, and connection category.

    Use the browser’s currentSrc and resource timing information where cross-origin timing policy permits. The W3C defines Resource Timing for performance data, while Google’s web-vitals library can help attribute Core Web Vitals in field monitoring.

    Connect browser observations to delivery policy using a stable asset ID or preset, not a secret token. The payload waste guide explains useful sizing calculations.

    Which alerts are actionable?

    Alert on sustained error-rate increases, high latency percentiles, old queued work, cold-transform surges, cache-hit collapse, private-origin rejection spikes, and a rise in LCP image load delay. Include a route, region, preset, or error class so responders have a starting point.

    Avoid paging on total traffic alone. A successful campaign can look like an incident. Use rates, ratios, saturation, and user-facing thresholds. Pair alerts with a short runbook that identifies relevant logs, a safe test asset, cache checks, and rollback controls.

    How do you control cardinality and privacy?

    Metrics labels must be bounded. Use known preset, status, format, region, and dimension buckets. Put asset IDs, request IDs, and raw diagnostic context in logs or traces with sampling and retention controls.

    Never log signing secrets, full bearer tokens, embedded origin credentials, or sensitive filenames by default. Hash or redact identifiers where business requirements allow. Restrict access to logs that reveal private asset usage.

    End-to-end observability is a correlation problem. A stable request context should connect the browser-visible result to edge delivery and backend processing without forcing every detail into one metric. When each stage emits a clear outcome, image incidents become a sequence of testable facts instead of a vague report that pictures are slow.

  • Protect remote image origins from SSRF

    Protect remote image origins from SSRF

    Short answer: Do not let a public image URL fetch arbitrary user-supplied destinations. Prefer registered source identifiers, restrict schemes and hosts, resolve and validate addresses, recheck redirects, block private networks, isolate egress, and enforce strict response limits.

    An origin-pull image service makes server-side requests on behalf of a caller. Without controls, an attacker may target internal services, cloud metadata endpoints, localhost, administrative interfaces, or large responses. Image decoding does not make the request safe.

    Prefer source IDs over arbitrary URLs

    The safest public interface accepts an approved asset ID or a path relative to a configured origin. The service looks up the actual base URL and credentials from trusted configuration. Callers cannot choose the scheme, host, port, or network destination.

    If a business workflow must import remote URLs, place it behind authentication and an ingestion job. Fetch once, validate, store the result as a managed asset, and serve future derivatives from that controlled source. The upload pipeline describes the validation stages.

    Avoid embedding remote credentials in public URLs. Configure origin authentication on the server and scope it to a narrow path.

    What should a URL allowlist validate?

    Allow only required schemes, normally HTTPS. Parse with a maintained URL library and reject ambiguous or malformed forms. Compare normalized hostnames against an exact allowlist or a carefully defined subdomain rule. Do not use a substring check.

    Disallow unexpected ports, user-info fields, IP literals, and fragments. Normalize internationalized domains consistently. Resolve DNS and reject loopback, link-local, private, multicast, and other nonpublic address ranges unless a specifically isolated private origin is part of the design.

    OWASP’s SSRF Prevention Cheat Sheet details allowlisting, network controls, and common bypasses. Apply the checks before each connection, not only when configuration is saved.

    Why must redirects and DNS be rechecked?

    An allowed public URL can redirect to a forbidden internal destination. Either disable redirects or validate every hop with the same policy. Limit the number of hops and do not forward origin credentials across hosts.

    DNS answers can change between validation and connection. Resolve through a controlled resolver, validate all returned addresses, and ensure the connection uses an approved result. Rebinding defenses need both application validation and network egress controls.

    Cloudflare documents its source-origin allowlist for image transformations. Product protections vary, so do not assume a managed fetcher exactly matches your allowlist requirements.

    What network controls provide defense in depth?

    Run fetch and decode work in an isolated environment with no route to internal control planes or metadata services. Use outbound firewall rules or a proxy that permits only approved destinations. Separate this worker’s identity from application and infrastructure credentials.

    Network controls remain valuable if URL parsing has a bug. Application allowlists remain valuable if network configuration changes. Neither layer should be the only barrier.

    Set connection, header, body, and total timeouts. Limit response bytes before buffering, verify the detected media type, cap decompressed pixels and frames, and abort slow streams. A valid public host can still return a decompression bomb or an endless response.

    How do signatures help?

    A signature can ensure that only a trusted application constructs a remote-fetch request. It does not make the destination safe by itself. The signer must enforce the allowlist and resource policy before issuing the URL, and the image service should still enforce its own limits.

    Use the signed URL policy to cover the approved source reference and transformation. Do not sign a base URL while leaving a redirect target or nested source parameter mutable.

    What should be logged and alerted?

    Log the normalized source ID, approved host, resolved public address, redirect count, response size, content type, timing, and rejection reason. Avoid logging embedded credentials, full signed tokens, or sensitive query strings.

    Alert on denied private addresses, repeated malformed hosts, unusual ports, redirect loops, high fetch failure rates, and sudden traffic to a new approved origin. Correlate source fetch logs with transformation requests through a safe request ID.

    The image pipeline observability guide describes broader operational signals. SSRF defenses should appear in the same dashboards and incident playbooks as reliability failures because attackers often look like unusual origin errors first.

    Remote fetching is a privileged server capability. Expose a controlled asset vocabulary to normal callers, isolate the component that performs network access, and make every rejected destination visible enough to investigate.

  • How to measure image payload waste

    How to measure image payload waste

    Short answer: For each image, compare its rendered CSS size and device-pixel ratio with the selected resource’s intrinsic dimensions, then examine transferred bytes, format, quality, and cache status. Aggregate the excess by component and page template so fixes target systems, not isolated files.

    An image can be wasteful in several ways. It may contain far more pixels than the slot needs, use an inefficient format, carry unnecessarily high quality, include unneeded metadata, or miss the cache. One number cannot diagnose all of them.

    What should you capture in the browser?

    Record the page URL, image element or component role, rendered width and height, device-pixel ratio, currentSrc, intrinsic width and height, encoded content length, transferred bytes, content type, loading priority, and timing. Also capture whether the image was the LCP element.

    The selected resource’s intrinsic dimensions can be compared with rendered dimensions multiplied by DPR. If a 400 CSS-pixel slot on a 2x device receives a 1600-pixel-wide file, the dimensional ratio is 2 relative to the 800-pixel physical need. That does not translate directly into twice the bytes because content and encoding matter, but it identifies a sizing problem.

    MDN documents currentSrc, naturalWidth, and related properties on HTMLImageElement. Browser performance APIs and developer tools can provide timing and transfer information, subject to cross-origin timing permissions.

    How do you estimate avoidable bytes?

    The most reliable method is to generate an appropriate comparison derivative for the actual slot, using the same crop, format, and quality policy. Compare its encoded size with the selected response. The difference is a concrete opportunity rather than a geometric guess.

    At scale, you can approximate dimensional waste from area ratio and flag large outliers for exact regeneration. Do not claim that halving width always quarters transfer size; image entropy, format headers, encoder settings, and responsive crop all affect the result.

    Separate cache transfer from representation size. A browser memory-cache hit may transfer zero bytes but the underlying resource can still be oversized for first-time visitors. Record encoded object bytes as well as observed network transfer.

    Which root causes should reports distinguish?

    Classify oversize selection, missing responsive candidates, inaccurate sizes, source upscaling, format fallback, excessive quality, cache miss, and duplicate request. Each maps to a different owner and fix.

    Oversize selection often points to the sizes attribute or a sparse width ladder. Too many near-identical variants points to variant explosion, not insufficient candidates. A heavy correctly sized image may need format or quality work.

    Duplicate requests can come from a preload that does not match final markup, a URL mutation during hydration, or two visually overlapping elements. A waterfall view is more informative than a byte inventory in that case.

    Lab audit or field measurement?

    Use both. Lab runs provide detailed, repeatable traces across chosen viewports, DPRs, and network conditions. They make it easy to inspect markup and test a candidate fix. Field data reveals the actual distribution of layouts, devices, routes, and cache states.

    Google’s Lighthouse documentation describes its properly size images audit, which is a useful diagnostic starting point. Do not stop at the score; trace flagged resources back to the component and delivery policy.

    In field monitoring, sample image observations to control volume. Aggregate by stable component name and preset, not by full signed URL. Full URLs can have high cardinality and may contain sensitive tokens.

    How do you prioritize fixes?

    Estimate total impact as avoidable bytes per view multiplied by affected page views, then consider whether the image is render-critical. A moderate saving on the LCP image may be more valuable than a larger saving far below the fold. Also prioritize systemic fixes that improve many assets.

    Start with wrong sizes, missing candidates, and unconstrained sources. Then review format and quality. Finally address smaller metadata opportunities. This order tends to deliver meaningful savings without lowering visible quality.

    Segment by mobile and desktop. An average can hide a mobile layout that routinely downloads desktop candidates. Review upper percentiles and top offending templates, not only the global mean.

    How do you prove the fix worked?

    Repeat the same lab scenarios and compare selected URLs, intrinsic dimensions, bytes, and timings. Confirm that visual quality and layout stability remain acceptable. Then watch field distributions after rollout.

    Use versioned transformation URLs so old cached objects do not contaminate the comparison. Track cache hit ratio and cold-transform rate; a new policy that saves bytes but creates many one-off derivatives may shift cost elsewhere.

    Image payload waste becomes manageable when it is described as a chain of evidence: slot, selected candidate, representation, transfer, and page role. That evidence points directly to the responsible component, markup rule, or image policy.

  • Prevent image variant explosion

    Prevent image variant explosion

    Short answer: Restrict transformations to an approved vocabulary, snap dimensions to a shared ladder, canonicalize equivalent requests, and require signatures for expensive or uncommon operations. Monitor unique variants per asset so a mistake is visible before it becomes a cost problem.

    On-demand image processing is powerful because a caller can ask for exactly what a layout needs. It becomes dangerous when every pixel value, crop, quality number, and query ordering creates a new stored derivative and a cold encode.

    Where do excessive variants come from?

    Responsive code may pass the current viewport width directly, producing values such as 731, 732, and 733. Editors may create a new preset for each campaign. Device-pixel-ratio logic can multiply widths again. Query parameters can be serialized in different orders. Attackers can deliberately request random combinations.

    Even legitimate features create a cross-product. Ten widths multiplied by four crops, three quality tiers, and three formats already allow 360 outputs for one source. Most applications use only a small fraction.

    The problem affects transformation CPU, storage, cache hit ratio, purge scope, and logs. It can also lengthen cold responses for real users if abusive work competes for processing capacity.

    How do width ladders and presets help?

    Map arbitrary requested widths to an approved responsive width ladder. The application can round up to the next candidate so visual quality is preserved. Enforce the same mapping on the server or signing layer, not only in a client helper.

    Use named presets for repeated crop and quality intent. A product-card-v1 preset is easier to audit than free-form width, height, gravity, sharpen, and quality fields. Keep lower-level operations available only to trusted administrative workflows that need them.

    Cloudinary documents named transformations as a reusable option in its transformation documentation. Provider features differ, but the governance principle is portable.

    Why is canonicalization required?

    Restrictions do not help if one allowed transform has many spellings. Normalize aliases, parameter order, numeric precision, default values, and source versions. Reject unknown fields. The cache key design guide explains the relationship between canonical input and stored identity.

    Do this before signing. A signature for raw, noncanonical strings can authorize duplicate representations. A central URL builder should emit exactly one string for one normalized request.

    If an edge cache and transformation service apply different normalization, inspect both. A provider may reuse one derivative internally while the CDN still stores many copies under raw URLs.

    Which limits should be enforced?

    Set maximum input pixels, output pixels, width, height, frame count, effect count, and processing time. Block upscaling beyond a deliberate threshold. Restrict remote origins and file types. Apply tighter rules to unauthenticated traffic.

    Use rate limits and quotas on derivative creation, not only total requests. A million requests for one warm thumbnail are cheaper than ten thousand unique expensive transforms. If the service exposes a cache-status or generated-variant signal, use it to distinguish them.

    For public URLs, consider signing any transformation outside a small allowlist. Expiry can control access, but a signature that permits arbitrary dimensions still allows a trusted caller or leaked token to create enormous variety. Sign policy-bounded inputs.

    OWASP’s guidance on denial of service provides the broader availability context. Image-specific limits translate that principle into measurable resource boundaries.

    What should you monitor?

    Track unique normalized transformations per source, new derivatives per minute, cold-transform latency, processing failures, transformation CPU if available, stored derivative bytes, and cache hit ratio. Segment by application, route, preset, and credential.

    Alert on rates and concentration. One source suddenly receiving thousands of widths is different from a planned catalog import. The top assets by variant count and the top transformations by creation rate are especially actionable views.

    Record rejection reasons. A spike in invalid widths may reveal a frontend bug rather than an attack. Sample raw requests safely so engineers can trace the caller without storing sensitive tokens.

    How do you clean up existing excess?

    First stop creation by enforcing the new policy. Deleting variants while callers still generate them only adds churn. Then identify derivatives that do not match approved normalized transformations and have not been requested within a retention window.

    Understand the provider’s deletion semantics. Removing a derivative may cause regeneration on the next request. Removing a source is materially different and can be irreversible. Test cleanup on a small asset cohort and retain a report of affected keys.

    Use the payload measurement workflow to confirm that a smaller set still serves appropriate resources. Variant reduction should not force every slot to download the largest image.

    On-demand transformation works best as a constrained API, not an infinite image calculator. A finite ladder, reviewed presets, canonical URLs, resource limits, and clear telemetry preserve the flexibility users need without accepting unbounded work.

  • Design a reliable image upload pipeline

    Design a reliable image upload pipeline

    Short answer: Accept uploads through a controlled endpoint or signed direct-upload flow, validate the real file, assign a stable asset ID, store the original, extract trusted metadata, and move the asset through explicit processing states. Make every retry idempotent.

    An upload endpoint is not finished when it returns a URL. It creates a source asset that future transformations, cache keys, editorial records, and deletion workflows depend on. A fragile ingestion model spreads that fragility across the entire delivery system.

    Direct upload or application proxy?

    In an application-proxy flow, the browser sends bytes to your server, which validates and forwards them. This gives the application tight control but consumes its bandwidth, memory, and request time. Large uploads can compete with normal API traffic.

    In a direct flow, the application issues a short-lived signed authorization and the client uploads to the media service or object store. This reduces application data transfer, but the server must still own policy and record completion. Do not give the browser a long-lived administrative credential.

    Cloudinary documents authenticated and unsigned methods in its upload guide. If unsigned presets are used, restrict them carefully because they represent a public capability. Provider-specific controls should map to your application’s policy, not replace it.

    What should be validated?

    Validate file size, detected media type, dimensions, pixel count, frame count, and allowed encoding. Do not rely only on the filename extension or client-provided Content-Type. Decode with maintained libraries in a resource-limited environment and fail closed on malformed content.

    Apply separate limits for animated images and high-resolution sources. A modest compressed file can expand into an enormous pixel buffer. Set time, memory, and dimension ceilings before expensive processing.

    Treat metadata as untrusted input. Strip metadata that is unnecessary for delivery, especially location data, while preserving fields your workflow deliberately needs. Normalize orientation before downstream crop logic if that is part of the platform contract.

    OWASP’s File Upload Cheat Sheet provides a broad security checklist. Adapt it to image-specific decoding and transformation risks.

    Which identity should the asset receive?

    Use a stable opaque asset identifier that does not depend on a mutable filename. Store the original filename as metadata if editors need it. Include a source version or content hash in delivery identity so replacing bytes does not silently reuse old derivatives.

    Deduplication can be helpful but should be explicit. Two users uploading identical bytes may not imply shared ownership or lifecycle. A content hash can detect repeats while business records remain separate.

    The upload response should return your canonical asset model, not a raw provider payload. Include asset ID, version, width, height, format, status, and safe preview information. The typed URL builder can consume that stable model.

    Which states make failure recoverable?

    Use explicit states such as initiated, uploading, received, validating, ready, rejected, and failed. Persist the state before asynchronous work starts. Each worker should be able to retry without creating another logical asset or overwriting a newer version.

    Assign an idempotency key to the upload intent. If a client retries after a lost response, return the existing result. For multipart upload, track parts and finalization separately. Expire abandoned intents and incomplete uploads through a scheduled cleanup policy.

    Do not publish a delivery URL until the source is validated and the required metadata exists. A placeholder status response is safer than letting the first public request discover a corrupt original.

    Should derivatives be generated during upload?

    Generate only predictable, high-value derivatives eagerly. A primary thumbnail, moderation preview, or guaranteed hero size may justify precomputation. Generating the full cross-product of widths, crops, qualities, and formats wastes work for variants never requested.

    On-demand generation is effective when the allowed set is bounded and cold latency is acceptable. The first-request behavior described in the cold path guide should inform which critical derivatives you warm.

    What should operations monitor?

    Track upload attempts, accepted bytes, rejection reasons, validation duration, processing duration, ready rate, orphaned intents, retry count, and storage growth. Correlate application upload IDs with provider request IDs without exposing secrets.

    Alert on a sustained rise in decode failures, timeouts, or assets stuck in a transitional state. A queue depth graph alone is not enough; age of the oldest item usually signals user impact more clearly.

    Provide administrators a safe retry and quarantine workflow. Preserve enough diagnostic metadata to understand failure, but do not retain malicious or rejected files indefinitely without a policy.

    A reliable upload pipeline creates a trustworthy asset before delivery begins. Stable identity, strict validation, explicit state, and idempotent recovery are what make later transformations and migrations routine instead of risky.

Share with