Short answer: use tenant-scoped private storage and short-lived signed URLs for original logistics receipts; publish only sanitized avatar derivatives behind a public CDN URL when the business has explicitly classified those profile images as public. The split should follow the object’s disclosure cost, not a single storage setting for the whole auth app.
That distinction matters in a logistics system because “image upload” hides two very different records. A courier avatar is a replaceable presentation asset. A receipt is evidence: the original bytes may be needed for an audit, a dispute, or a replay of the extraction pipeline. Making both public improves cacheability at the price of turning a key into the access-control boundary. Making both private protects the receipts, but signed avatar URLs expire and fragment shared caches.
I’ve been paged by missed jobs and duplicate deliveries. The storage lesson is the same as the scheduling lesson — preserve an immutable fact, make each transition idempotent, and treat every derived view as disposable. For this system, the invariant is simple: an original receipt never crosses into a public delivery namespace.
What should an auth app use for private avatar storage: signed URL or public CDN URL?
There isn’t one best option for every user profile image. A public CDN URL is appropriate only when anyone who obtains the stable URL is allowed to fetch the image. A signed URL is appropriate when each read needs a bounded authorization decision, because the URL carries temporary access rather than making the object generally readable.
That sounds obvious. It isn’t once browser caching, tenant membership, deletion, and retries enter the path.
Start with a classification table and make the policy executable:
| Object class | Canonical copy | Delivery path | Cache policy | Tenant rule |
|---|---|---|---|---|
| Receipt original | Private, immutable object | Short-lived signed URL after authorization | Private or no-store | Request tenant must match object tenant |
| Receipt preview | Private derivative | Signed URL or authenticated image proxy | Bounded private cache | Same as original |
| Courier avatar source | Private object | Never delivered directly | No direct cache | Owner tenant only |
| Sanitized avatar derivative | Separate delivery object | Public CDN URL, if classified public | Long-lived, versioned URL | No confidential tenant data in key or pixels |
The catch is that “unguessable” is not an authorization policy. A random object name reduces accidental discovery, but forwarding a public URL still forwards access. Conversely, a signed URL is also a capability: until it expires, anyone holding it may be able to use it within the conditions attached to the signature. The application must therefore authorize before issuing it, keep its lifetime short enough for the risk, and avoid storing that temporary URL as the permanent profile-image field. AWS documents that its presigned URLs grant time-limited access and can be reused until expiration; that behavior is a useful model even when the underlying implementation differs.
Store a stable object ID and version in the database. Resolve delivery at read time.
The incident invariant: keep evidence out of the presentation path
The dangerous failure is not a slow thumbnail. It is a receipt original becoming reachable under the same public rules as a courier portrait. Once that happens, changing a database flag does not necessarily retract copies already held by browsers, intermediary caches, logs, or recipients. Cache invalidation can reduce exposure, but it cannot prove that every fetched copy disappeared.
My runbook starts at the namespace boundary. A receipt key contains the tenant ID and an immutable receipt ID, while a public avatar key contains an opaque subject ID plus a content version. The public key excludes names, email addresses, shipment IDs, tenant slugs, and original filenames. More importantly, the service account that writes public avatar derivatives has no operation that can copy a receipt original into the public namespace. This is a permission boundary, not a naming convention.
Consider the retry path. A mobile client times out after uploading a receipt, retries, and a queue delivers the processing message twice. If each attempt creates a new canonical object, the audit trail now has competing “originals.” If image processing overwrites the source, later extraction cannot be reproduced from the received bytes. The preventative design accepts an idempotency key scoped to the tenant, computes a digest while streaming, commits one immutable original, and records derivative versions separately. A repeated request returns the established object identity; it does not silently create another fact.
Keep it boring.
The same rule handles avatar replacement without weakening receipt retention. Upload a new private avatar source, validate and normalize it, write a new public derivative under a versioned key, then atomically update the profile’s current version. Old public versions can age out under a documented retention policy. The URL changes when the bytes change, so a long cache lifetime does not require purging the current image in place.
Put tenant authorization before signing
Signing should be the final step after object lookup and tenant authorization. It must not accept a caller-supplied storage key and merely wrap that key in a signed URL. That shortcut turns a subtle object-reference bug into a direct cross-tenant read.
The following Go sketch keeps policy at the application boundary. The storage implementation may use an object store, an internal gateway, or a self-hosted service; the handler does not rely on a vendor-specific route.
package media import ( "context" "errors" "time" ) type Class string const ( ReceiptOriginal Class = "receipt-original" AvatarPublic Class = "avatar-public" ) type Object struct { ID string TenantID string Class Class Key string Version string } type Catalog interface { Find(ctx context.Context, objectID string) (Object, error) } type Signer interface { SignRead(ctx context.Context, key string, expiresAt time.Time) (string, error) } type Delivery struct { URL string ExpiresAt *time.Time } var ErrForbidden = errors.New("object is not available to this tenant") func ResolveDelivery( ctx context.Context, catalog Catalog, signer Signer, requestTenant string, objectID string, publicBaseURL string, now time.Time, ) (Delivery, error) { obj, err := catalog.Find(ctx, objectID) if err != nil { return Delivery{}, err } if obj.TenantID != requestTenant { return Delivery{}, ErrForbidden } switch obj.Class { case ReceiptOriginal: expiresAt := now.Add(5 * time.Minute) url, err := signer.SignRead(ctx, obj.Key, expiresAt) if err != nil { return Delivery{}, err } return Delivery{URL: url, ExpiresAt: &expiresAt}, nil case AvatarPublic: return Delivery{URL: publicBaseURL + "/" + obj.ID + "/" + obj.Version}, nil default: return Delivery{}, ErrForbidden } } Five minutes is an example policy value, not a universal optimum. Set the lifetime from the longest legitimate fetch, clock skew, client behavior, and the cost of a leaked capability. I’m not sure a mobile network trace from one region can establish that value for a global fleet; production latency percentiles and failed-fetch telemetry would resolve it. Don’t extend expiry merely because the UI cached the signed URL in a profile row. Fix the data model instead.
Notice another deliberate choice: the example checks tenant equality even for an avatar whose derivative is public. The resolver is an authenticated profile API, so it should not become a directory for enumerating other tenants’ subjects. Once a known public URL is returned, the CDN can serve it without an application authorization check. Those are separate decisions.
Test revocation, replay, and cache behavior as one system
Unit tests for the signing function are necessary and insufficient. The deployment gate needs cross-tenant negative tests: tenant A cannot request tenant B’s receipt by object ID; an avatar source is never resolved to a public URL; a retired receipt reference cannot be reassigned; and duplicate upload commands converge on one canonical original. Run those cases against the same authorization middleware and storage policy used in production.
Then test time.
A signed receipt URL should work before its expiry and fail after it according to the storage service’s documented semantics. Removing a user from a tenant does not inherently revoke a URL already issued, so high-risk workflows may need very short expiry or an authenticated proxy that checks membership on every request. That proxy gives tighter revocation and audit visibility, but it adds an application hop, capacity planning, and another availability dependency. It is not suitable when large public images need broad cache reuse and per-request authorization has no business value.
For public avatar derivatives, verify that a profile update produces a new versioned URL, that the previous version is no longer referenced by the application, and that cache headers match the retirement window. “Delete now” and “cache for a year” are conflicting requirements unless the architecture includes purge controls and the organization accepts their limits. Your mileage may vary because privacy obligations, employment rules, and contractual retention differ; legal and security owners must set those boundaries.
Observability should follow object identity without leaking capabilities. Log tenant ID, object ID, class, policy decision, signer outcome, and expiry duration. Do not log the full signed query string. Alert on denied cross-tenant reads, unusual signing volume, processing lag, duplicate idempotency keys with different digests, and any attempt to route a receipt class through public delivery. A request ID ties the upload, queue message, derivative job, and delivery decision together during a postmortem.
Cost still matters, but compare architecture-shaped costs rather than a single storage rate. Private delivery may incur signing operations, object reads, and reduced shared-cache efficiency. Public CDN delivery may reduce origin traffic while increasing purge and governance work. An authenticated proxy adds compute and outbound traffic. Use actual request sizes, cache-hit ratios, retention periods, and regional transfer paths. Published object-storage pricing separates several of these dimensions, so a workload model is more useful than comparing one headline rate.
Choose the boundary, then document the exceptions
Default receipt originals to private, immutable, tenant-scoped storage. Issue signed URLs only after authorization, and keep their expiry aligned with the task. Default avatar sources to private too; publish a sanitized, versioned derivative only when the product’s privacy classification permits anonymous viewing. This preserves an audit-grade original path while allowing profile images to benefit from stable CDN caching.
Stick with signed delivery for avatars when they reveal membership, role, location, or another fact that should disappear promptly after authorization changes. Use an authenticated image proxy when immediate centralized revocation outweighs the extra hop. A public CDN URL is the wrong option for receipts and for any profile image whose possession is not meant to imply perpetual access.
Write these exceptions into the runbook: who may reclassify an object, how old avatar versions retire, what happens after tenant removal, and which event proves receipt ingestion completed. The design survives an incident when an operator can answer those questions without guessing.


