Generate a fixed set of WebP derivatives from each approved product photo, and make the transformation recipe part of their stored identity. The deciding constraint is the number of objects a marketplace agrees to retain after background removal, including photos reused as blog covers.
TL;DR: For a Node.js application with an Express delivery layer, define three allowed widths, generate them from the approved master, and return a manifest for the responsive source set. Keep arbitrary dimensions out of the public transformation contract. Budget derivative storage, cache variants, and telemetry separately; each has a different retention decision.
This decision record uses 320, 640, and 1280 pixels as proposed widths. They are example policy values, not measured requirements. A marketplace should replace them after reviewing its product cards, detail pages, and cover layouts. WebP supports transparency, according to the MDN image format guide, so a transparent background-removal result can remain transparent in these derivatives. That format capability does not establish acceptable edge quality for a particular catalog.
How should we generate three WebP widths without multiplying retained objects?
The invariant is a bounded recipe: one approved master produces at most three published derivative objects for one active recipe revision. Background removal precedes this recipe. Derive each width from that master rather than resizing an already reduced output. The proposed encoder policy preserves aspect ratio and alpha, fixes its quality settings, and declines to enlarge a source smaller than the requested width. These are application requirements, not defaults attributed to an image library.
Count the retained objects.
For a sufficiently large master, the chosen policy creates three derivatives plus the master. Keeping an older recipe revision adds another three derivatives until that revision expires. If both the original upload and the approved background-removed master are retained, count both. A storage estimate that silently treats them as one object has already lost track of its unit.
An image smaller than 1280 pixels exposes a useful boundary. Under this policy, the manifest contains only the widths actually generated; it never labels a smaller image as 1280 pixels wide. The delivery contract therefore promises up to three candidates. If the application requires exactly three, enforce a minimum master width at ingestion and report that requirement to the uploader. Do not hide enlargement inside a supposedly fixed recipe.
The stored identity should include the approved master revision and the recipe revision. A replacement master or a changed encoding policy gets new derivative identities. A page can then refer to a specific manifest without interpreting an old URL as a different image. This spends storage during revision overlap in exchange for a simpler relationship between a URL and its bytes.
Keep the overlap explicit.
Without an expiry decision for superseded revisions, a bounded width list still permits unbounded historical storage.
The alternatives and their retention consequences
The relevant comparison is when the system commits to a derivative, not which image-processing package it imports. The following options describe application designs, with their corresponding obligations.
| Design | Storage commitment | Cache identity | Appropriate boundary |
|---|---|---|---|
| Generate the approved set at ingestion | Up to three objects per master and recipe revision | Master revision, recipe revision, width | Catalog layouts with a known candidate set |
| Generate an allowed width on first request | Only requested candidates initially | The same bounded identity | Large catalogs where many approved candidates may never be requested |
| Accept arbitrary requested dimensions | A separate possible object for every accepted size combination | Every accepted transformation parameter | A controlled editing workflow with quotas and expiry |
The first option is the decision here. It commits storage before demand is known, but lets the application validate the entire candidate set before advertising it to a product page or a blog cover. Demand remains uncertain. The second can defer work and storage. It also requires a policy for simultaneous first requests and for a candidate that is not yet available.
Neither option makes an unused derivative free to keep. The proposed retention job starts from active master and recipe revisions, then identifies superseded objects after an explicitly chosen grace period. That period should cover the application's own page and cache lifetime policies. This is a deployment obligation: shortening retention without considering existing references can leave pages pointing to deleted images.
A critical path with a bounded request contract
The Express layer should expose an application-owned contract and leave encoder selection behind it. The curl example below defines a proposed local interface; it is not an existing public API or a claim about a library's options. Implement its validation and generation behavior before using these requests. The fixture must be an approved, background-removed master at least 1280 pixels wide if all three candidates are expected.
curl --fail-with-body \
--request POST \
--header 'Accept: application/json' \
--form 'master=@approved-product-master.png;type=image/png' \
--form 'recipe=product-webp-v1' \
http://localhost:3000/image-sets/catalog-photo-001
curl --fail-with-body \
--header 'Accept: application/json' \
http://localhost:3000/image-sets/catalog-photo-001
The first request submits one master under an illustrative catalog identifier. The recipe name selects server-owned settings: WebP output, the three allowed widths, aspect-ratio preservation, alpha preservation, and no enlargement. Clients cannot add a fourth width by appending a request parameter. Bind this operation to the marketplace's authenticated upload workflow rather than making arbitrary public uploads part of image delivery.
In the proposed contract, the submission succeeds only after the generated candidates have passed validation and their manifest is available. The second request reads that manifest. Its candidate entries carry a URL, actual pixel width, actual pixel height, media type, and encoded byte count. Those are requirements for this application interface. No particular response schema is implied by curl itself.
The page renderer constructs a width-descriptor source set from the returned URLs and actual widths, and supplies a sizes value that describes the rendered layout. Keep a fallback image URL as well. This is the integration point for the reader implementing responsive images in Node.js and Express: return verified candidates, then render the responsive markup from them. Blog covers and product cards may share bytes when their geometry and transformation policy agree. A cover needing a different crop requires a distinct recipe, which must enter the object count.
Publication follows validation.
Before publishing the manifest, decode each output and check its declared dimensions, format, and expected transparency behavior. Use fixture photos with fine edges and transparent margins to assess the background-removal result after encoding. A completed HTTP request alone is insufficient evidence of acceptable image content. For errors, return a bounded application error category and retain enough correlation data to investigate; do not publish a manifest containing candidates that failed validation.
Retention arithmetic includes the logs
Consider a planning example with 10,000 accepted masters per day. Assume the three encoded derivatives together occupy 240,000 bytes per master, and assume every day's derivatives remain active for 30 days. That is 72,000,000,000 bytes, or 72 GB in decimal units, of derivative payload. These inputs are hypothetical accounting assumptions, not WebP compression measurements. They exclude masters, historical revisions, metadata, replication, and cache copies. Measure encoded output from representative marketplace photos before turning the estimate into a capacity commitment. For example, a recipe experiment that retains a complete second set for the same 30 days would add another 72 GB under these assumptions. Calling that experiment temporary does not change its retained bytes; deleting its superseded outputs does. Record its expiry when the experiment begins, and keep its outputs out of the active manifest until they are approved.
Now account for observability.
Under a separate hypothetical policy of one 400-byte event per generated derivative, the same volume produces 12,000,000 bytes of event payload daily. Seven days retain 84,000,000 bytes, or 84 MB in decimal units, before indexing or replication. Changing the image retention policy does not change that telemetry budget. Keeping request logs indefinitely would be a separate decision with a separate growth curve.
Metric labels deserve the same discipline. Three width values crossed with two outcome values create six possible combinations before adding any other dimensions. Identifiers change that. Adding a photo identifier creates a series space that grows with the catalog. The proposed metric design therefore uses bounded width and outcome labels; photo identifiers belong in selectively retained diagnostic records. Recipe revisions also need a retirement policy if they are used as labels.
Sampling is a trade-off. Counting every generation outcome supports an aggregate failure rate, while retaining only a sample of successful diagnostic events reduces the detail available for reconstructing an individual success. Keep validation-failure diagnostics under a separate, bounded policy, and document the success-sampling probability. A sample cannot promise a complete history of every photo. If that history is required, give it an explicit retention budget instead of treating sampled logs as an audit ledger.
The acceptance test should include a replacement master and a recipe revision, not just three successful output files. Verify that previous pages retain their intended candidates during the overlap period and that retired revisions become eligible for deletion afterward. Review actual derivative bytes, retained revisions, and diagnostic volume together after deployment, because an encoder change that reduces individual file sizes can still increase the retained total if it adds a second recipe whose outputs remain available beside the first set for the full retention period.
Deletion matters too.
The rejected option still has a use case
Arbitrary dimensions are rejected for this catalog delivery path because they remove the fixed upper bound on derivative variants. A seller-facing crop editor is a valid separate use case: exploratory dimensions can be useful before approval. Give those previews a quota and expiry, then submit only the approved master to the published recipe.
The decision holds while the marketplace can describe its published layouts with a small candidate set. Revisit the widths when layout evidence changes. Keep the governing rule: every retained image, cache variant, and diagnostic record needs an identity and a lifetime that someone can explain.
References
- MDN, Image file type and format guide: https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
Top comments (0)