KatInterview

Secure Client-Direct Attachment Uploads for a Messaging Product

System DesignModel answer
MediumModel answerSystem Designsystem-designobject-storagepresigned-urls

Last updated

Design a pipeline where clients send files straight to object storage using scoped signed URLs, with a tracked lifecycle, async scanning and processing, and cleanup of abandoned uploads.

Context

A team messaging product lets people attach everything from small screenshots and avatars to large video clips and archives. Pushing all of that data through the regular API tier would strain memory, inflate bandwidth bills, and make long transfers fragile on flaky connections.

Design an upload system in which clients send bytes directly to a cloud object store (S3 or GCS style), while the backend still controls who may upload, checks what was uploaded, and tracks each file's lifecycle.

What the system must do

Functional

  • Hand clients short-lived, narrowly scoped upload permissions (for example presigned URLs) without ever exposing the storage account's main credentials.
  • Persist each file's state through these stages: INITIATED, UPLOADED, PROCESSING, ACTIVE, FAILED, EXPIRED.
  • Verify files (checksum, content-type detection, malware scanning) and build derivatives (thumbnails, video transcodes) asynchronously, so a file only becomes usable in chat after it passes.
  • Find and delete leftovers: uploads that were started but never finished, and files whose processing failed.

Non-functional

  • Security: block disallowed file types, prevent overwriting existing objects, and prevent access across channels the user does not belong to.
  • Scalability: handle peak upload starts while using very little backend compute.
  • Reliability: retries and resuming large uploads must not create duplicate objects or database rows.

Scale

  • 20 million daily active users
  • 5 million uploads per day, roughly 200 per second at peak
  • Images up to 25 MB; videos and archives up to 1 GB
  • Files in active channels are kept indefinitely unless a user or retention policy deletes them

Cover in your answer

  1. The request/response flow between client, backend, and object store for both single-request and multipart uploads.
  2. The data model for upload sessions, file records, channel associations, and state.
  3. The event pipeline: storage notifications, background workers, and how the client learns about progress and completion.
  4. Failure handling and garbage collection: interrupted uploads, checksum mismatches, and storage events that arrive late or never.

Hints

Hint 1

Keep the rule 'file bytes never pass through API servers' central: the backend only authorizes, records state, and decides. Let the server choose the object key and bake size, content type, and checksum constraints into the signed request.

Hint 2

Treat the file record as a state machine where every transition is a conditional update (compare-and-set on the current state). That makes duplicate or out-of-order storage events harmless, and an idempotency key on session creation makes client retries safe.

Hint 3

Upload into a private quarantine location first, and only copy to permanent storage after verification. Add a periodic reconciler that checks storage directly, so lost events and abandoned multipart uploads are both caught.