Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

Users upload files up to 5 GB through a JAX-RS service that currently receives the whole multipart body, stores it to a temp directory and then copies it to object storage. Pods run out of disk and uploads time out. Redesign it.

I would take the bytes off the service: the JAX-RS service issues pre-signed upload URLs, using multipart upload in S3-compatible storage, and the client uploads the parts directly to storage. The service keeps only control endpoints to create an upload, complete it and check its status, and it validates files asynchronously after upload (size, type, virus scan), exposing them only when they pass. If proxying is truly unavoidable, it streams parts straight to storage without temp files with consistent body and timeout limits at every layer, and abandoned uploads are cleaned up with lifecycle rules and idempotent completion calls.

Why this question is asked

The current design fails for predictable reasons: each 5 GB upload sits on the pod's disk while it arrives, then again while it is copied, and a single slow client holds a request thread and a connection for an hour. Interviewers ask this design question to see whether we recognise that the service should not be in the data path at all, and whether we can design the control flow, security and cleanup around that. In this answer, we will see why the current design breaks, design direct uploads with pre-signed URLs, define the control endpoints, move validation after upload, cover the fallback when proxying is required and handle abandoned uploads.

1Why the Current Design Breaks

Let us follow one upload. The client sends a 5 GB multipart body. The runtime's multipart parser writes the file part to a temp directory, so the pod's disk holds 5 GB. Then our code copies the temp file to object storage, which takes more minutes while the disk is still full. With ten parallel uploads, the pod needs 50 GB of ephemeral disk, and Kubernetes evicts it when it runs out, failing every upload on that pod.

Timeouts come from the chain of components. At 20 Mbit/s, a 5 GB upload takes over half an hour. The load balancer, the ingress proxy, the API gateway and the server each have their own body size and idle or request timeouts, and the smallest one wins. A single failure at 90 percent means starting again from zero, because one HTTP request cannot resume.

2Moving the Bytes Off the Service

Object storage such as Amazon S3, Google Cloud Storage or an S3-compatible system like MinIO is built to receive large files. Its multipart upload splits a file into parts, in S3 between 5 MiB and 5 GiB each and up to 10,000 parts, uploaded independently and in parallel, and then joined into one object. A pre-signed URL is a URL that carries a signature created with our service's credentials, which allows exactly one operation, such as PUT of one part of one object, until it expires.

So the service decides who may upload what, and the storage receives the bytes. The pods never see the file, so their disk and threads are no longer involved, and a failed part is simply retried on its own.

Step throughDirect upload with pre-signed URLs
ClientUpload serviceObject storage
POST /uploads {name, size, type}
create multipart upload for key uploads/u-123
uploadId and pre-signed part URLs
PUT part 1..N directly (parallel, retried)
ETag for each part
POST /uploads/u-123/complete {part ETags}
complete multipart upload
202: status VALIDATING

8 messages in order. Play them, or step through them one at a time.

3The Control Endpoints

The JAX-RS service now has three small endpoints. Create upload checks that the user may upload, checks the declared size and type against limits, generates the storage key itself, starts the multipart upload and returns the upload id and URLs for the parts. Complete upload receives the list of part ETags, asks storage to assemble the object and moves the upload to a validating state. Status returns where the upload is: in progress, validating, available or rejected.

Java
@Path("uploads")
public class UploadResource {
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response create(UploadRequest req) {
UploadTicket t = uploads.start(currentUser(), req); // key generated server-side, size <= 5 GB
return Response.created(uriFor(t.id())).entity(t).build();
} // 201 {"id":"u-123","partSize":67108864,"parts":[{"n":1,"url":"https://..."}, ...]}
@POST @Path("{id}/complete") @Consumes(MediaType.APPLICATION_JSON)
public Response complete(@PathParam("id") String id, CompleteRequest req) {
UploadStatus s = uploads.complete(currentUser(), id, req.parts()); // idempotent
return Response.accepted(s).build(); // 202 {"status":"VALIDATING"}
}
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)
public UploadStatus status(@PathParam("id") String id) { return uploads.status(currentUser(), id); }
}

Notice that complete is idempotent: if the client's network drops after it sends the request, it can call complete again and gets the same answer instead of an error. That matters because the client will retry, and a non-idempotent completion would make retries risky.

4Validating After the Upload

Because the bytes never passed through our code, we cannot check them on the way in, so we check them afterwards. The object lands in a quarantine location that nobody can download from. A storage event or the complete call triggers a worker that verifies the real size matches the declared one, sniffs the content type from the first bytes, runs a virus scan, and only then marks the file available, possibly moving it to its final location. If any check fails, the file is rejected and deleted, and the status endpoint says why.

This is a good design in its own right. Scanning a 5 GB file can take minutes, and doing it asynchronously means no HTTP request waits for it.

5If Proxying Is Unavoidable

Sometimes the bytes must pass through us, for example when clients cannot reach the storage network or a regulation requires inline inspection. Then we stream: read the request body as a stream, cut it into parts of, say, 64 MB in a small reusable buffer, and upload each part to storage as it fills, so the pod never holds more than a part or two in memory and nothing goes to disk. Multipart form parsing that buffers to temp files must be avoided, for example by accepting the file as a raw application/octet-stream body.

And the limits must agree along the whole path: load balancer, ingress (for example request buffering turned off so the proxy does not spool the body itself), gateway and server, each with the same maximum body size and idle timeouts long enough for slow clients. One component with a 60-second timeout or a 1 GB limit breaks everything behind it.

6Cleaning Up Abandoned Uploads

Many uploads are started and never finished: the user closes the laptop or loses the network. In S3, the parts of an incomplete multipart upload are stored and billed until the upload is aborted. A lifecycle rule that aborts incomplete multipart uploads after, for example, 7 days removes them automatically, and another rule deletes rejected files from quarantine. On our side, a scheduled job marks uploads in progress for longer than the URL validity as expired, so the status endpoint stays truthful and the client knows to start again.

7Follow-up questions

How do you authorize a pre-signed URL safely?

The service checks the user's permission before signing, and the URL itself is as narrow as possible: one HTTP method (PUT), one object key that the server generated rather than the client, one part number, HTTPS only, and a short expiry, such as 15 to 60 minutes, with new URLs issued for later parts if needed. Where the storage supports it, a presigned POST policy can also limit the content length range. We also apply per-user quotas when creating uploads, because anyone with a URL can use it until it expires.

Why not just raise the timeouts and disk size?

That treats the symptom. Uploads would still fail entirely on any network hiccup, pods would still need disk proportional to concurrent uploads, and each slow client would still hold a thread for the full transfer. Direct upload removes all three problems.

How does the client know which part size to use?

The service chooses it in the create response, for example 64 MiB, which gives 80 parts for a 5 GB file and stays well within the 10,000-part limit while keeping a retry cheap.

8Conclusion

In this answer, we saw that 5 GB uploads through the service fill pod disks and hit timeouts at every layer, and that the fix is to move the bytes off the service. Clients upload parts directly to object storage with pre-signed multipart URLs, while the JAX-RS service keeps create, complete and status endpoints, validates and scans asynchronously from quarantine, and exposes files only when they pass. If proxying is required, we stream parts without temp files with consistent limits, and lifecycle rules plus idempotent completion handle abandoned uploads.

What to say in the interviewAbout 100 seconds aloud

Open with

The core problem is that the service is in the data path. Every 5 GB upload goes to the pod's temp disk and then gets copied again, so a few concurrent uploads fill ephemeral storage, and a half-hour transfer runs into whichever of the load balancer, ingress, gateway or server has the shortest timeout, with no way to resume.

Then, if they want more

I would move the bytes off the service using object storage multipart upload with pre-signed URLs. The client calls POST /uploads with name, size and type; the service checks permissions and limits, generates the storage key itself, starts a multipart upload and returns an upload id plus pre-signed URLs for the parts, say 64 MB each.

The client uploads the parts directly and in parallel, retrying any failed part, then calls complete with the part ETags. Complete is idempotent, so a retried call is safe, and it puts the upload into a validating state.

A worker then checks the real size, sniffs the type, runs a virus scan in a quarantine location, and only then marks the file available; a status endpoint reports progress. The pre-signed URLs are narrow: one method, one key, HTTPS, short expiry. For abandoned uploads I would add a lifecycle rule that aborts incomplete multipart uploads after a few days.

If we truly had to proxy, I would stream chunks straight to storage with no temp files and make body limits and timeouts consistent at every layer.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Jakarta EE specifications
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Users upload files up to 5 GB through a JAX-RS service that currently receives the whole...": https://scrivio-interview-library.netlify.app/java/jax-rs/29c45c05e7/