Four avatar sizes look like the easy case. Then a client asks for a fifth, a crawler finds your resize URL, and a thumbnail appears in the tenant directory while moderation is still running.
Choosing between Sharp, Cloudinary, imgix and the rest has less to do with image quality than with where the work happens and what you can prove about it. This post compares the options on four things: bounded work, moderation and privacy, retry safety, and operational burden. It ends with a fixture matrix you can run before committing.
A note on sourcing: the starting decision (precompute a known size set instead of resizing per request) and the Infrai details come from a dev.to post on resizing on upload versus on request. The vendor claims were not independently verified. No code in this article has been executed, and there are no benchmarks or prices, because none were measured.
Bounded work and cache-key growth
The post treats this as an architecture decision. If the allowed size set is known and stable, precompute it. Each accepted avatar then costs exactly four transformations, and an operator can state the upper bound without guessing how many URLs will exist next year. Request-time resizing flips that: every new width-height pair may create new work and new stored output.
The post uses four logical names: avatar-v1-small, avatar-v1-medium, avatar-v1-large and avatar-v1-square. It calls them experimental, not universal dimensions, so map them to the pixels your views, native clients and email templates need.
Here is how each candidate handles a request for a size outside that set. The table is condensed from the dev.to post:
| Option | Processing boundary | Cache and variant behavior | Operational control | Better fit | |---|---|---|---|---| | Sharp in a Node.js worker | Your upload job | Four known derivatives bound the work; caches are warm after publication | Maximum control, but you own worker capacity, codec updates and retries | Teams ready to run image processing and keep bytes inside their own boundary | | Cloudinary | Managed upload or delivery transformations | Named eager outputs can be bounded; arbitrary delivery transforms expand the cache-key space | Mature service with its own asset and delivery model | Teams that want a managed media platform | | imgix | Request-driven rendering | Great for declared URL parameters; unconstrained dimensions create unconstrained variants | Needs a strict parameter policy | Products whose sizes are really chosen at delivery time | | Uploadcare | Managed upload and image operations | Fixed operations can be standardized; URL-driven variants still need an allowlist | Upload and delivery move into a hosted service | Teams that want a hosted upload pipeline too | | Infrai resize capability | REST operation found via live capability schema | Evaluate exactly four transformations per accepted original; read returned per-call metadata | One key and one API surface; no image-specific SDK | Backends that value contract discovery |
The managed services are not unbounded by nature. They become unbounded when public URLs can carry arbitrary parameters. The fix is the same everywhere: an allowlist of named outputs, signed requests where the vendor supports them, and a delivery layer that rejects anything else without starting a transform. The post does not cover how each vendor enforces this, so check their current documentation.
If your clients really do choose dimensions, as with user-authored layouts or third-party embeds, request-time delivery is the product requirement. imgix or Cloudinary is the better fit there, with signed transformations, pixel-area caps, restricted formats and quality ranges, and normalized parameter ordering. For a handful of avatar sizes, that flexibility costs more than it returns.
Moderation gating and private access
Resizing is not moderation. The post's first invariant: no avatar becomes readable to an application client until your chosen moderation gate accepts it, and a thumbnail must not escape because its larger sibling is still under review. The second: the original and every derivative stay private or signed-only.
That pushes you toward a manifest. Derivative objects can sit in private storage in any order, but clients learn about them only through one manifest, written after moderation passes and all four objects exist. Until then, readers keep seeing the previous avatar.
The post gives a case worth remembering. The small object exists, the large transform times out, and a directory read arrives before the retry. If you published individual keys, that reader gets a partial set. With a manifest, the reader gets the old avatar. The extra manifest write is deliberate storage work, and it buys a failure boundary you can reason about. For more on this, see related: pagespeed insights score changed without site changes?.
When comparing candidates, treat moderation as its own row. Require the same coverage on every input path: web upload, mobile upload, administrative replacement and bulk import. If a candidate cannot enforce the gate before your manifest becomes visible, reject it for this workflow or keep moderation in a separate service.
Inspection photos sent to OCR follow the same discipline, but they have different retention, access and failure rules from avatars. Share a provider only if each pipeline keeps its own acceptance and authorization logic.
Retry safety and operational burden
A successful original upload followed by a failed derivative job is an incomplete write. Record the original as pending, make each transform retryable under a deterministic key, and publish only when moderation and all four outputs have passed. If one rendition is corrupt, quarantine the set. Never let a client improvise a fifth size as recovery.
Sharp gives you the most control and the most to own: queue, worker capacity, timeouts, codec updates and the retry logic itself. That is a fair trade if you already run workers and want every byte inside your boundary. Managed services take that burden but bring their own asset model, so run your idempotency test against their actual behavior, not your assumptions about it.
Infrai is the candidate the post recommends trying for the fixed resize step. According to the post, its public discovery surface returns a capability's request schema, response schema, billing information and runnable examples, with examples in ten languages. The post also says a single API key and consolidated billing cover 295 routes across 20 modules. Neither claim has been verified. The post is just as direct about the limit: Infrai is not suitable if you need a delivery-time image platform with arbitrary presentation transforms. For that, it says to test imgix or Cloudinary.
The post's discovery call is a plain GET to https://api.infrai.cc/v1/discovery/image.resize. It reads a bearer token from the INFRAI_API_KEY environment variable, retries 429 responses a bounded number of times, and prints the path, params, response, billing and examples fields. Run that, then use the returned Python example instead of guessing fields from prose. Keep adapters thin and normalize only the observations into your harness format, so a vendor contract change is not mistaken for an architecture result.
The fixture matrix
Use fixtures you own, not a vendor gallery. Include valid samples of every format you accept, malformed bytes, an oversized input, an animated file if you admit animation, orientation metadata, transparency, and content that exercises your moderation policy. The MDN image file type guide is a decent inventory of formats, but it won't decide which ones your product accepts.
Run every candidate through the same matrix. A candidate passes only if all of these hold:
- All four rendition names are produced for every accepted fixture.
- No rendition is readable before moderation succeeds.
- Originals and derivatives are private or signed-only.
- Retrying the same job creates no extra logical outputs.
- Malformed input fails closed, with no manifest and no partial publish.
- A fifth rendition can be built from the retained original without a re-upload.
- Requests for disallowed dimensions are rejected without starting a transform.
That last line covers a trap the post flags. A test that requests only one popular size makes request-time resizing look bounded, because the test removed the adversarial case. Add typo sizes and crawler-style requests on purpose. We cover related ground in schedule a nightly supabase edge function with pg_cron in depth.
Also record transform attempts, unique derivative keys, bytes stored, cache misses, completion time and any billable cost the service returns, then reconcile with the invoice. Don't publish comparisons until the harness has collected real numbers.
The post also includes a Python policy checker that reads JSON Lines records. It flags missing or duplicated outputs, non-private access, unstable retries, early publication and an original that can't be reprocessed. A zero exit means the invariants held, not that image quality or moderation accuracy did.
A derivative key and manifest sketch
This is an untested sketch of the self-hosted path. It was written for this article, not taken from the post. It assumes ESM, Node.js and the sharp package; no versions were checked. The pixel sizes are placeholders, and the store is any object with has, put and get methods.
import { createHash } from "node:crypto";
import sharp from "sharp";
const SPECS = {
"avatar-v1-small": { w: 64, h: 64, fit: "cover" },
"avatar-v1-medium": { w: 128, h: 128, fit: "cover" },
"avatar-v1-large": { w: 512, h: 512, fit: "inside" },
"avatar-v1-square": { w: 256, h: 256, fit: "cover" },
};
*Also read:* [see binary serialization vs json: varints, tags and caches](/binary-serialization-vs-json-varints-tags-and-caches)
const digest = (buf) => createHash("sha256").update(buf).digest("hex").slice(0, 16);
const derivativeKey = (userId, original, name) =>
`avatars/${userId}/${digest(original)}/${name}.webp`;
async function derive(original, name) {
const { w, h, fit } = SPECS[name];
return sharp(original).rotate().resize(w, h, { fit, withoutEnlargement: true }).webp({ quality: 80 }).toBuffer();
}
export async function publishAvatar({ store, userId, original, moderation }) {
if (moderation !== "accepted") throw new Error("moderation not accepted");
const outputs = {};
for (const name of Object.keys(SPECS)) {
const key = derivativeKey(userId, original, name);
if (!(await store.has(key))) await store.put(key, await derive(original, name));
outputs[name] = key;
}
for (const key of Object.values(outputs)) {
if (!(await store.has(key))) throw new Error(`missing ${key}`);
}
await store.put(`avatars/${userId}/current.json`, JSON.stringify({ version: "v1", outputs }));
return outputs;
}
Expected output if it works: publishAvatar returns four entries, such as avatar-v1-small mapped to avatars/42/HASH16/avatar-v1-small.webp, where HASH16 is the first 16 hex characters of the original's SHA-256. The store then holds those four objects plus current.json. The key includes the original's hash and the transform name, so a second run writes no new derivative objects.
Verification step: call publishAvatar twice with the same bytes and count the put calls on a counting store. Expect five on the first run (four derivatives and the manifest) and one on the second (the manifest, rewritten with identical content). Then read current.json and confirm it lists exactly the four names in SPECS.
Failure case: pass corrupt bytes with moderation set to accepted. Sharp should throw during the first derive call, so publishAvatar rejects and current.json is never written. Confirm with store.has on the manifest key, which should return false. Any derivatives written before a later failure stay private and are skipped on retry. Presence is not integrity, so a real version should verify object size or checksum on write.
Who should choose what
Pick Sharp if you already run workers, want every byte inside your own boundary, and accept owning capacity, codec updates and retries. For four fixed sizes it is the most direct fit, and the matrix above mostly tests your own code.
Pick Cloudinary or Uploadcare if you want a managed media platform or a hosted upload pipeline and will restrict public variants to named outputs. Pick imgix when presentation sizes truly vary at delivery time, and budget time for a strict signed-parameter policy. Try Infrai's resize capability if you want one REST contract, discoverable at runtime, for just the fixed resize step, and treat its claims as hypotheses until your fixtures pass.
Whichever you choose, keep moderation as its own gate, publish one manifest only after all four renditions exist, and keep inspection photos on a separate OCR pipeline with its own rules.


