← Building blocks

Upload large files without touching your servers

Networking & deliveryfundamental

Uploads stream through API servers, which become a bandwidth bottleneck.

Say it like this

API servers should never carry upload bytes, so the client asks for short-lived pre-signed URLs and sends the file straight to object storage in resumable parts, and the server only validates and records the result.

Basic solution

Issue a short-lived pre-signed URL; the client uploads straight to object storage in resumable parts.

S3 pre-signed URLsmultipart uploadtus protocol

Bytes bypass the API

The API hands out signed part URLs and steps aside. Parts go straight to object storage in parallel; the complete call assembles, validates and enqueues. A lifecycle rule cleans up abandoned parts.

How it works

  1. The client calls POST /v1/videos with the title, declared size and content type. The API inserts a video row with status uploading, and asks object storage to start a multipart upload, which returns an upload id that identifies this upload until it is completed or aborted.
  2. The API signs one URL per part. Each URL encodes the bucket, the key, the part number, the HTTP method and an expiry (say 1 hour), plus an HMAC signature over all of that computed with the storage secret. Signing is local arithmetic; it needs no call to storage. For a 5 GB file that might be 50 URLs for 50 parts of 100 MB.
  3. The client PUTs the parts directly to object storage, several in parallel. Storage checks each URL's signature, accepts the bytes, and returns an ETag (a checksum identifier) for that part. If one part fails, the client retries only that part; the others are already safe.
  4. When every part is done, the client calls POST /v1/videos/{id}/complete with the list of part numbers and ETags. The API passes that list to storage, which assembles the parts into one object. The API then validates the result: it compares the stored size against the declared size, checks the checksum, and reads the first megabyte of the object to confirm the container format and codec are what the client claimed.
  5. If validation passes, the API sets the row's status to processing and enqueues a transcoding job. Uploads that never reach complete are cleaned up by a lifecycle rule on the bucket that aborts incomplete multipart uploads after a few days, so abandoned parts do not accumulate.

Why the signature works

  • The URL carries the bucket, key, method, expiry and a signature over them. Storage recomputes the signature with the same secret and rejects any URL that was altered, so the client can perform exactly that one operation on exactly that one key, and only until the expiry.

Worked example

Video streaming uploads

  • 500K uploads/day, average 1 GB: 500 TB/day, about 46 Gbps average ingest, 3× at peak.
  • Through API servers: at 10 Gbps per server you would need 14 servers at peak doing nothing but copying bytes, and every mobile network drop would restart a 1 GB transfer. Direct to object storage: the API fleet handles 500K small JSON calls a day plus 500K completes, which one small instance could serve.
  • Parts: 1 GB in 10 MB parts is 100 parts, uploaded 4 to 8 at a time. On a 20 Mbps mobile link the upload takes about 7 minutes; a drop at minute 6 costs one 10 MB part, not 1 GB.
  • Signing cost: 100 signatures per upload × 500K uploads = 50M HMACs/day, each microseconds. The signed URL list is about 30 KB, returned once.
  • Validation: the complete call reads the first 1 MB of the object to probe container and codec, checks the declared size against the stored size and the client-supplied checksum, and rejects within a second before any transcoding minutes are spent.

Variants and when each wins

Pre-signed PUT per part (multipart)

  • The file is split into parts, each with its own signed URL, uploaded in parallel and retried individually. It wins for anything over a few tens of megabytes, because a dropped connection costs one part instead of the whole file.

Single pre-signed PUT

  • One signed URL and one request for the whole file. It wins for small files such as avatars and documents under about 100 MB, where simplicity matters more than resumability; any failure restarts the whole upload.

POST policy upload

  • The server signs a policy document that constrains the allowed content type, size range and key prefix, and the browser submits the file as a form. It wins when you want storage itself to enforce those limits before it accepts a single byte.

Resumable protocol (tus) or storage-native resumable sessions

  • An upload server or the storage service tracks how many bytes have arrived, and the client asks where it left off and continues from there. It wins on very unreliable networks; the cost is either a stateful upload service to run or a dependency on a storage feature that supports it.

Recommendation: multipart with pre-signed part URLs; single PUT for small files; a policy or size cap on every signature so a client cannot upload more than it declared.

Failure modes

Abandoned multipart uploads

  • Storage cost keeps growing even though the number of visible videos does not. Clients that start an upload and never call complete leave their parts sitting in the bucket, invisible to listings but still billed. Add a lifecycle rule that aborts incomplete multipart uploads after N days, and run a nightly job that marks the matching video rows as failed.

Corrupt or wrong file accepted

  • Transcoding fails hours after upload, or a user uploaded a 5 GB zip file as a video. The complete call accepted whatever arrived without checking it. Verify the stored size and checksum against what the client declared, probe the file header for the container and codec, enforce an allowlist of content types, and reject with a clear error before any transcoding job is enqueued.

Expired signature mid-upload

  • The last few parts of a large upload fail with 403 on slow connections. The signed URLs expired because the expiry was shorter than the time a realistic upload takes. Size the expiry to the file (hours for large files), and provide an endpoint that re-signs the remaining parts for the same upload id so the client can continue without starting over.

Signature grants more than intended

  • A client overwrites another user's object, or uploads far more than it declared. The signed key was chosen by the client, or the signature carried no size constraint. Let the server choose the object key, sign each part with a content-length condition or use a POST policy with a size range, and reject at complete if the stored object is larger than declared.

Hot-spotting storage prefixes

  • Uploads start failing with throttling errors during a spike. Every key shares the same sequential prefix, so all the writes land on one storage partition that has not yet scaled. Put a hashed or random component at the front of the key so writes spread across partitions; most object stores now scale per prefix automatically, but a date-only prefix is still a risk at very high rates.

Interviewer follow-ups

Answer out loud before you open each one.

How do you know the upload is complete and not corrupt?

The complete call is the only signal. The server assembles the parts, compares the stored size and checksum with what the client declared, and probes the file header to confirm it is the type claimed. Until that passes, the video row stays in uploading and nothing downstream runs.

How does resume work after a network drop?

The client keeps the upload id and the list of parts with their ETags. On reconnect it asks the server which parts storage already has (or lists them), re-signs any expired URLs, and uploads only the missing parts. Only the part in flight at the drop is repeated.

Why not let the API server proxy the bytes and validate inline?

Every byte would cross the API fleet twice (in and out to storage), so the fleet is sized by bandwidth instead of by requests, and a dropped connection loses the whole transfer. Validation inline is also not better: you can validate the assembled object just as well after the fact.

What stops a malicious client from uploading forever?

Each signature is bound to a server-chosen key, a method, an expiry and, with a POST policy or content-length condition, a maximum size. The server also records the declared size in the video row and rejects at complete if the stored object is larger, and quotas limit uploads per account.

Connections

In study paths
Video from upload to play
Pairs with
Keep large blobs out of the database · Separate metadata from bytes · Move slow work off the request · Process uploads in parallel · Validate at the edge
Pulls against
Put a reverse proxy in front
Used in
Video Streaming Platform (YouTube / Netflix)

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon EC2 Auto ScalingUpload APICompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon DynamoDBMetadata DBFirestore, BigtableCosmos DBScyllaDB, Apache Cassandra
Amazon S3Object storageCloud StorageBlob StorageCloudflare R2, MinIO, Ceph
Amazon SQSTranscode queuePub/Sub, Cloud TasksService Bus queues, Queue StorageRabbitMQ, ActiveMQ