TL;DR: Send small avatar images as one object. Multipart upload adds session state, retries, and cleanup that a tiny file rarely earns. For a developer tool that also retains signed documents, the harder boundary is different: record an explicit deletion deadline beside every accepted object, then make deletion observable and testable.
The useful size threshold is not a magic number copied from a provider page. It is a decision made from measured transfer failure, memory limits, and the storage service's multipart constraints. Start with one request. Introduce parts only after evidence shows that retrying the whole object is the unreliable step.
That is intentionally boring. I judge upload paths by time-to-first-call, and extra configuration has to defend itself.
One request. One result.
Why doesn't a small image need multipart upload?
Multipart upload solves a specific problem: a large transfer can be split so failed work can be retried in smaller units. An avatar is usually cleaner as one object because one request has one success boundary. There is no upload session to persist, no part ordering to coordinate, and no abandoned multipart state for a cleanup job to find.
Do not turn "usually" into an undocumented byte constant. Measure representative files over the networks your users actually have. Record object size, total duration, retry count, and failure class. Then choose the smallest policy that meets the service objective. A slow connection may justify resumability before a fast data-center connection does; a runtime with a tight memory ceiling may require streaming even when it does not require multipart. Those are separate choices.
Presigned URLs can keep file bytes off the application server. AWS documents that they grant time-limited access using the permissions of the principal that created them and can be reused until expiration. Treat one as a bearer capability. Bind the object key on the server, keep its lifetime aligned with the upload flow, and never let the browser select another tenant's namespace.
The URL moves bytes. It does not prove that the file is valid or entitled to indefinite retention. This approach also has a hard limitation: a single transfer retries from the beginning after an interrupted connection. If measured failures make those restarts unacceptable, use a resumable or multipart protocol even when the file would be considered small elsewhere. Conversely, multipart is a poor fit when session bookkeeping, part cleanup, and client complexity cost more than the occasional full retry. The trade-off is recoverable progress versus operational state, not "modern" versus "legacy."
For signed documents, that distinction matters more than raw throughput. GDPR Article 17 describes a right to erasure and lists exceptions. Legal applicability needs qualified review, but the engineering shape is clear: deletion should be an explicit state transition, not a vague promise hidden in storage configuration.
Build the smallest policy layer
Start with two decisions: which transfer mode to use, and when the object becomes eligible for deletion. The first can evolve from measurements. The second comes from the product's retention rule and must be recorded at acceptance time.
This TypeScript core has no SDK imports or provider flags. The threshold is injected, so a deployment can set it from benchmark results instead of source-code folklore.
type TransferMode = "single" | "multipart";
type UploadPolicy = {
multipartAtBytes: number;
maximumBytes: number;
};
type AcceptedObject = {
objectKey: string;
sizeBytes: number;
transferMode: TransferMode;
retainUntil: string;
};
function chooseTransferMode(sizeBytes: number, policy: UploadPolicy): TransferMode {
if (!Number.isSafeInteger(sizeBytes) || sizeBytes < 1) {
throw new Error("sizeBytes must be a positive safe integer");
}
if (sizeBytes > policy.maximumBytes) {
throw new Error("file exceeds the configured upload limit");
}
return sizeBytes >= policy.multipartAtBytes ? "multipart" : "single";
}
function acceptObject(input: {
objectKey: string;
sizeBytes: number;
retainUntil: Date;
policy: UploadPolicy;
}): AcceptedObject {
if (input.retainUntil.getTime() <= Date.now()) {
throw new Error("retainUntil must be in the future");
}
return {
objectKey: input.objectKey,
sizeBytes: input.sizeBytes,
transferMode: chooseTransferMode(input.sizeBytes, input.policy),
retainUntil: input.retainUntil.toISOString(),
};
}
The server generates objectKey. That closes a common isolation hole: a client must not overwrite a predictable key by changing a form field. The server validates declared size before issuing upload authority, then verifies the stored object's actual size and media type after upload. Image decoding belongs in that verification step; trusting a filename or browser-supplied MIME type is weak validation.
A signed document needs an acceptance record, but immutability and perpetual storage are not synonyms. Put the retention deadline in an application database that can be queried and audited. Object metadata may duplicate it for operations, yet it should not be the only copy because reconciliation needs a dependable index.
Make deletion a first-class operation
A lifecycle rule is a useful backstop. It is not a complete deletion workflow. The application still needs to show which object was due, when deletion was attempted, and what happened. Keep that ledger free of document contents and upload credentials.
Backstops can fail quietly.
type RetainedObject = {
objectKey: string;
retainUntil: string;
};
interface ObjectStore {
deleteObject(objectKey: string): Promise<void>;
}
interface RetentionRepository {
dueBefore(isoTime: string, limit: number): Promise<RetainedObject[]>;
markDeleted(objectKey: string, deletedAt: string): Promise<void>;
markForRetry(objectKey: string): Promise<void>;
}
async function deleteDueObjects(
store: ObjectStore,
repository: RetentionRepository,
now: Date,
): Promise<void> {
const due = await repository.dueBefore(now.toISOString(), 100);
for (const item of due) {
try {
await store.deleteObject(item.objectKey);
await repository.markDeleted(item.objectKey, now.toISOString());
} catch {
await repository.markForRetry(item.objectKey);
}
}
}
The batch limit of 100 is an implementation control, not a storage recommendation. Tune it against worker timeouts and service quotas. More important, make deletion idempotent: deleting an already absent object should converge on the same application state as deleting it once. The repository should claim work so two workers do not race, and retry scheduling should use bounded backoff.
Alert on the age and count of overdue records, not merely worker exceptions. Reconcile the object index against storage inventory. Keep clocks synchronized, use UTC instants, and define whether retainUntil is inclusive. A deadline with ambiguous semantics is config debt wearing a compliance badge.
There is also an authorization edge. A user-requested erasure may require deletion before the ordinary deadline, while a valid exception may block it. Model those outcomes explicitly. Do not silently extend retainUntil; record the authority, reason category, and review time without putting sensitive free-form text into logs.
Test the boundary and scale only with evidence
Boundary tests should cover one byte below the configured threshold, exactly at it, the maximum accepted size, and invalid sizes. That checks the comparison operator, which is the sort of tiny choice that otherwise survives until production.
import { strict as assert } from "node:assert";
const policy = { multipartAtBytes: 8_000_000, maximumBytes: 40_000_000 };
assert.equal(chooseTransferMode(7_999_999, policy), "single");
assert.equal(chooseTransferMode(8_000_000, policy), "multipart");
assert.throws(() => chooseTransferMode(40_000_001, policy));
Those numbers are test fixtures, not universal recommendations. Replace them with a threshold supported by measurements and compatible with the chosen storage interface. Benchmark the full path: requesting upload authority, transferring bytes, server-side verification, and finalizing the application record. A fast transfer followed by a slow verifier is still a slow user experience.
Deletion deserves failure injection. Make the object-store adapter time out, report an already-absent object, and succeed after a retry. Advance a fake clock across the deadline. Verify that no deletion happens early, that a due object eventually reaches deleted, and that logs contain an object identifier and result without containing the signed document or credential.
Database success and object-store success are not one transaction. Persist deletion intent first, perform the external deletion, then mark completion. A periodic reconciler repairs interruptions between those steps. Hiding this distributed boundary behind a giant transaction abstraction adds glue without removing the failure mode.
This design has limits too. A database ledger adds a worker, retry state, reconciliation, and an on-call signal; for data with no explicit retention deadline, that machinery may be needless. A storage lifecycle policy can be the smaller choice when coarse expiration is sufficient and application-level completion evidence is not required. At the other extreme, a regulated archive may require controls beyond this example, including reviewed holds and independently preserved audit evidence. The code here is a policy boundary, not legal advice and not a complete records-management system. That distinction matters because automatic deletion can be as damaging as indefinite retention when a valid hold applies. Pick the mechanism only after the organization has defined who may set, shorten, extend, or block a deadline.
At higher volume, separate acceptance, verification, and deletion into queued jobs with explicit states. Derive the transfer threshold per deployment from benchmark distributions instead of exposing a forest of per-tenant switches. Multipart becomes justified when measurements show that resumable part retries materially improve completion for the supported file distribution. Once enabled, persist upload-session state, cap concurrency, verify completion, and abort abandoned sessions.
The decision rule stays blunt: use one-shot uploads for small images until measured conditions justify multipart; stream when memory requires it; keep authorization on the server; and attach signed-document deletion to a durable deadline plus an idempotent worker. Benchmark the boundary. Delete on schedule.
Further reading
- AWS S3 User Guide, Presigned URLs: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
- GDPR Article 17, Right to erasure: https://gdpr-info.eu/art-17-gdpr/
Top comments (0)