DEV Community

SuttonHawkins6723
SuttonHawkins6723

Posted on

How to Compare Cloud Storage Providers for Direct Browser Uploads — Go

Short answer: compare the tenant boundary before comparing upload latency. For a logistics receipt workflow, the browser should receive a short-lived upload URL for one server-selected object key, while the storage policy must prevent that URL from crossing tenants. S3, Cloudflare R2, and Wasabi can all be evaluated through that same contract because the important test is the trust boundary: who chooses the bucket, key, headers, and expiry, and what happens when a client retries?

I have been paged by missed jobs and duplicate deliveries. Those alerts changed how I look at direct uploads. A successful HTTP response is not proof that the receipt is attached to the right shipment. A retry can create a second object, and a copied upload URL can expose another tenant's prefix. The provider comparison belongs after those cases are defined.

What can a browser upload safely?

The browser needs permission to send bytes, not permission to invent identity. The application authenticates the operator, resolves the tenant and shipment on the server, and creates an object key from trusted values. The response can contain an upload URL, an expiry, and the exact headers the browser must send. It should not accept a client-supplied bucket or an arbitrary key as an authority decision.

For example, the key can be derived from an internal tenant ID and receipt ID:

package upload

import "fmt"

func receiptKey(tenantID, receiptID string) string {
    return fmt.Sprintf("receipts/%s/%s/original", tenantID, receiptID)
}
Enter fullscreen mode Exit fullscreen mode

That function is deliberately boring. Its input should already be validated identifiers, not a path copied from the browser. Keep the original file under a stable key, record the expected content length and media type in the database, and make the receipt ID idempotent. If the request is retried, the service returns the same pending upload record instead of creating a second logical receipt.

CORS is part of the browser contract, not an access-control substitute. The storage endpoint must allow the application origin and the required request method and headers, while the authorization decision remains in the signed request and storage policy. MDN's CORS guidance is useful here because a browser may block a response even when the server received the request; that is an operational failure mode worth testing separately.

Where did the tenant boundary fail?

The incident shape is easy to reproduce. Tenant A requests a receipt URL, then a worker or test tool changes the key to receipts/tenant-b/... before sending the request. A second case uses a valid URL after its intended expiry. A third sends a different content type than the one signed. These are not throughput tests. They answer whether the URL represents one narrow capability or a general storage credential.

I start with a matrix and keep the expected result explicit:

Test Expected result Why it matters
Valid key and signed headers Upload succeeds Confirms the normal browser path
Key changed to another tenant Rejected Tests tenant isolation
Signed URL after expiry Rejected Limits copied links
Same receipt request repeated Same logical receipt Prevents duplicate delivery records
Interrupted large upload resumed One finalized object Tests retry behavior

The last row deserves care. A multipart upload is a sequence, not one request. S3's multipart documentation describes separate initiation, part uploads, and completion, which means the application needs a cleanup policy for abandoned uploads. The browser can retry a part, but the service still needs to know which receipt owns that upload and when an incomplete upload should be removed.

Here is the server-side shape I use for the authorization decision. The signer is intentionally an interface, so the same test suite can exercise different S3-compatible backends without turning the article into a provider setup guide.

package upload

import (
    "context"
    "errors"
    "fmt"
    "time"
)

type Signer interface {
    PresignPut(ctx context.Context, bucket, key, contentType string, expires time.Duration) (string, error)
}

type ReceiptRequest struct {
    TenantID    string
    ReceiptID   string
    ContentType string
}

func CreateUpload(ctx context.Context, s Signer, r ReceiptRequest) (string, string, error) {
    if r.TenantID == "" || r.ReceiptID == "" || r.ContentType == "" {
        return "", "", errors.New("missing receipt identity or content type")
    }

    key := receiptKey(r.TenantID, r.ReceiptID)
    url, err := s.PresignPut(ctx, "receipts", key, r.ContentType, 10*time.Minute)
    if err != nil {
        return "", "", fmt.Errorf("presign receipt upload: %w", err)
    }
    return key, url, nil
}
Enter fullscreen mode Exit fullscreen mode

The ten-minute value is an example policy, not a universal setting. Choose it from the expected upload duration, clock skew, and the consequences of a leaked URL. Persist the key and an upload state such as pending, complete, or expired; do not infer completion solely from the browser's callback. A worker can verify the object metadata, then atomically mark the receipt complete.

How should I compare cloud storage providers for direct browser uploads?

The protocol surface is similar enough to make a common test harness practical, but “S3-compatible” does not mean identical operations or identical operational behavior. S3 is the reference point for the multipart and lifecycle concepts in the supplied documentation. R2 exposes an S3-compatible API and documents presigned URLs, while Wasabi documents presigned URL workflows. For this use case, the difference to measure is the surrounding behavior: endpoint configuration, policy language, CORS controls, multipart limits, lifecycle cleanup, and the observability available to explain a rejected upload.

I would record the result as evidence rather than as a ranking:

Provider surface Check in the harness Decision signal
S3 API behavior Presigned PUT, multipart completion, lifecycle rule Does the workflow match the retention and cleanup model?
R2 S3-compatible endpoint Signature, endpoint, CORS, multipart behavior Are endpoint-specific settings explicit in deployment configuration?
Wasabi S3-compatible endpoint Signature, bucket policy, CORS, multipart behavior Can the same tenant-denial tests run without hidden exceptions?

No row answers tenant isolation by itself. A bucket policy can be carefully written and still be undermined by an application that signs the wrong key. Conversely, an application can derive the right key and still fail browser uploads because CORS does not allow the signed headers. Keep those layers separate in logs and tests.

Avoid making price the deciding argument. Storage and request economics change, and the receipt workflow has costs that a headline comparison misses: abandoned multipart parts, reprocessing, audit retention, cross-region movement, and the engineer-hours needed to diagnose a provider-specific rejection. A neutral comparison should carry those variables as measured inputs, not as a permanent cheapest-provider claim.

What should happen when the browser or worker retries?

A receipt has two identities: the business identity and the object identity. The business identity might be (tenant_id, receipt_id). The object identity is the server-derived key. Make the database uniqueness constraint match the first one, and make the key deterministic from it. That is the simplest guard against duplicate delivery records.

For completion, accept an event or callback only after checking the tenant, receipt ID, object key, size, and expected media type. Then use a compare-and-set transition so two workers cannot both perform the final side effect. The original file remains available for audit, while downstream processing can use a separate derived object or record.

A small state machine is easier to page on than a pile of booleans:

package upload

type State string

const (
    Pending  State = "pending"
    Complete State = "complete"
    Expired  State = "expired"
)

func CanComplete(current State, key, expectedKey string) bool {
    return current == Pending && key == expectedKey
}
Enter fullscreen mode Exit fullscreen mode

The real implementation must perform the transition transactionally and verify object metadata through the storage API. This helper only makes the invariant visible: an expired or already-complete receipt cannot be completed by a late retry.

For large files, use multipart upload only when the reliability benefit outweighs the cleanup and state-management cost. The browser needs a resumable plan; the service needs an abort path and a scheduled check for stale uploads. S3's lifecycle documentation covers lifecycle management as a storage-side control, but the application still needs a receipt state and an audit trail. Storage cleanup cannot tell you whether a shipment's original was successfully processed.

The runbook I would ship

First, log a request ID, tenant ID, receipt ID, object key, provider label, and upload state. Do not log the signed URL. Second, alert on pending receipts older than the normal upload window, failed completions by tenant, and growth in incomplete multipart uploads. Third, keep a replay-safe reconciliation job that compares pending records with object metadata and makes no assumption that one notification arrived exactly once.

Before deployment, run the matrix against each configured endpoint from a real browser origin. Repeat it after changing CORS, signing libraries, bucket policies, or endpoint settings. Include clock skew in the test environment. A green unit test around key construction is valuable, but it cannot prove that a browser preflight, signature check, and storage policy agree.

The advice has a boundary. If receipts are tiny, uploads are infrequent, and the server already handles the file safely, a direct browser path may add more lifecycle work than it removes. The trade-off is operational: this design does not fit a team that cannot maintain upload state, validate object metadata, or operate cleanup for abandoned multipart work; choose a server-mediated upload when that control plane would be simpler. If an auditor requires immutable retention, add the relevant retention and deletion controls to the decision record; a presigned URL is an upload mechanism, not an audit policy.

The provider choice should be the final implementation detail. The durable decision is that a tenant can upload only the object the server assigned, retries preserve one receipt identity, and operators can explain every pending or rejected upload. That contract gives S3, R2, and Wasabi a fair test, and it keeps a storage outage from becoming an accounting mystery.

Sources

Top comments (0)