DEV Community

KenjiTanaka6849
KenjiTanaka6849

Posted on

Object Storage Services for Image Resizing — A Guide to Avatar Uploads

Short answer: use object storage for originals and derivatives, then put image resizing in a worker or image service; choose the storage adapter by large-file throughput, resumable transfer, and deletion controls rather than by a resize label.

Image transformation storage is less about finding a bucket that magically resizes files and more about separating two different jobs: storing the original bytes and producing bounded, disposable derivatives. For an education platform retaining signed documents until an explicit deletion deadline, I would keep originals in object storage, resize avatar uploads in a worker or image service, and record the deadline against every object and derivative. The deciding constraint is large-file throughput. A convenient resize API does not compensate for a retention model that cannot prove deletion.

Which object storage services support resizing for avatar uploads?

The connection is operational. An avatar may be a small JPEG, while a signed enrollment packet can be a large PDF or a scanned image set. They can share an upload pipeline, but they should not share assumptions about lifecycle, retry behavior, or access.

That separation matters.

I have been paged for missed jobs and duplicate deliveries. The useful lesson is unglamorous: an upload event is a request to reconcile state, not permission to perform an irreversible side effect exactly once. A retry can arrive after the resize already succeeded. A deletion job can run after a late derivative was created. The design has to make both cases boring.

The first boundary is file ownership. Store the original document under an immutable key, keep the avatar source separate from its display variants, and persist a record containing the source key, derivative key, content type, checksum, and deletion deadline. The second boundary is processing. A resize worker reads a source, writes a new object, and records the result with an idempotency key such as source-version/width/height/fit. The third boundary is deletion. The deadline is evaluated for every key, including failed or abandoned uploads.

This is why “supports image resizing” is an incomplete storage requirement. Object storage can retain the source and the generated image. Resizing may happen in application code, a queue consumer, a CDN image layer, or a separate image-processing service. Ask where the bytes are transformed, where the result is addressed, and which system owns cleanup.

Which storage shape survives large-file throughput?

For large uploads, the important capability is resumable or multipart transfer. A single request is easy to demo and painful to recover when a client loses its connection near the end of a large scan. Multipart upload lets a client or upload service send parts independently, retry a failed part, and complete the object after all required parts arrive. The exact part limits and checksum options vary, so they belong in an adapter and a test matrix rather than in business logic.

The three mainstream object-storage families expose different names for similar mechanics. Amazon S3 documents multipart uploads. Google Cloud Storage documents resumable uploads. Azure Blob Storage uses block blob staging and commit operations. These are useful distinctions when selecting an adapter, but they do not answer the image question by themselves: each stores the original and the derivative; your transformation path still has to be defined.

Storage family Large-file path Image-resizing boundary Retention question
Amazon S3 Multipart upload Worker or image layer writes a derivative How are incomplete uploads and derivatives cleaned up?
Google Cloud Storage Resumable upload Worker or image layer writes a derivative Can lifecycle rules backstop the application deadline?
Azure Blob Storage Block blob staging and commit Worker or image layer writes a derivative Is block and derivative cleanup observable?

The table is a starting point, not a product ranking. The adapter still needs failure tests against the selected service.

For a high-throughput ingest path, I would measure four things with representative signed-document files: completed bytes per second, retry cost after a dropped connection, time from upload completion to derivative availability, and the number of unfinished uploads after a test run. A 12 MB avatar benchmark tells me almost nothing about a 900 MB scanned packet.

There is a trade-off here. Transforming synchronously gives the caller a simple response but couples upload latency to image work and makes retries harder to reason about. Transforming asynchronously adds a visible pending state, yet it keeps large-file ingestion independent from derivative generation. For this scenario, that separation is worth the extra state.

The preventative path: one event, many safe retries

A minimal worker can make the invariant explicit. The storage and image interfaces below are deliberately generic; an implementation can wrap any object store and any transformer without changing the retention record.

type ObjectStore interface {
    Get(ctx context.Context, key string) (io.ReadCloser, error)
    Put(ctx context.Context, key string, body io.Reader, contentType string) error
    Delete(ctx context.Context, key string) error
}

type Transformer interface {
    Resize(ctx context.Context, source io.Reader, width, height int) (io.ReadCloser, error)
}

func ProcessAvatar(ctx context.Context, store ObjectStore, transformer Transformer, sourceKey, variantKey string, width, height int) error {
    // The destination key is deterministic, so a redelivery targets the same result.
    source, err := store.Get(ctx, sourceKey)
    if err != nil {
        return err
    }
    defer source.Close()

    variant, err := transformer.Resize(ctx, source, width, height)
    if err != nil {
        return err
    }
    defer variant.Close()

    return store.Put(ctx, variantKey, variant, "image/jpeg")
}
Enter fullscreen mode Exit fullscreen mode

The code is intentionally incomplete at the edges. Production code also validates the input type, bounds dimensions, limits decompression work, checks the transformed content, and records a version or checksum before publishing a URL. It should not trust a filename extension to identify an image. It should not overwrite a source document with a derivative.

Idempotency does not mean the worker can ignore races. Two deliveries can process the same source concurrently. Use a conditional create, a versioned destination, or a result record that accepts the same successful checksum. If the output format or transformation policy changes, change the variant version too. Otherwise a policy change can silently reuse an old image.

The retry is expected.

The advice changes when the image is user-facing at very high volume and can be regenerated from a durable source. In that case, an edge transformation layer may be a better latency choice than precomputing every size. The deletion rule still applies: a cache or derivative must not extend the retention period of the signed source, and the system must know which copies it controls.

How should the deletion deadline cross the pipeline?

Put the deadline in application metadata and enforce it in more than one place. Object lifecycle rules can provide a backstop, but they are not a substitute for a queryable inventory of expected objects. The worker should reject a job whose source is already past its deadline. The deletion job should remove the source, derivatives, temporary multipart state, and metadata references according to the retention policy.

A practical record might contain these fields:

  • document_id and tenant or student scope
  • source object key and immutable source version
  • derivative keys and transformation version
  • deletion deadline in UTC
  • upload state, processing state, and last error
  • checksum and observed content length

Use a clock abstraction in tests. Create cases for a deadline exactly at the current instant, a retry after expiration, an upload that completes after its record was cancelled, and a deletion that is redelivered. The expected result should be explicit for each case. “The bucket probably expires it” is not an assertion.

Observability should follow the object, not only the queue message. Emit a correlation ID, source key hash, byte count, upload duration, transform duration, retry count, and deadline status. Avoid putting student identifiers or signed-document content into logs. Alert on age of the oldest pending upload, unfinished multipart work, derivative failures, and objects whose deadline has passed but still have a live metadata record.

Choosing an implementation without choosing a vendor

Start with interfaces and failure tests. Then compare the storage services on the capabilities that affect this workload: multipart or resumable upload behavior, checksum support, conditional writes, lifecycle controls, event delivery, audit visibility, and the way temporary upload state is cleaned up. A service that advertises image resizing may still require a separate transformation product or worker. Verify the complete path, including deletion of the derivative.

Keep the comparison evidence-based. Official documentation describes multipart upload for S3, resumable uploads for Google Cloud Storage, and block blob upload patterns for Azure Blob Storage. Those are transport and object-model differences, not a ranking. The correct choice depends on where the existing queue, identity boundary, audit system, and large-file traffic already live.

Run a failure exercise before committing: interrupt an upload after several parts, deliver the completion event twice, make the transformer fail once, advance the clock beyond the deletion deadline, and inspect the resulting object inventory. This catches more than a polished avatar demo.

The decision rule is straightforward: choose the storage adapter that can move the largest expected source reliably, make transformation asynchronous and deterministic, and make the deletion deadline a first-class state transition. Resizing is a feature of the pipeline. Retention is a property of the whole system.

Sources

Top comments (0)