Lesson 10 of 16
11. Object / Blob Storage

11.9 What happens after a file is uploaded?

3 min read+10 XP

At the cloakroom: When a coat comes in, a helper in the back brushes it, makes a ticket and files a photo, without making the guest wait at the counter.

In the system: Uploaded files often need processing: making thumbnails, converting videos to several qualities (transcoding, Chapter 40), scanning for viruses, extracting text from PDFs for search (Chapter 19). Doing this inside the upload request makes users wait and fails badly under load. Instead, use a pipeline:

upload, object-created event, queue, resize workers, three cover sizes, CDN.

Figure: the upload returns at once; workers do the heavy lifting in the background.

  1. The original is uploaded (originals/42.jpg).
  2. The store emits an "object created" event.
  3. The event lands on a queue (Chapter 22).
  4. Workers take jobs from the queue, make the sizes, and write them to new keys (covers/42/small.jpg ...). They scale on queue length (Chapter 6).
  5. The database is updated, and the site shows a placeholder until the sizes exist.

Make each job safe to run twice (writing the same output key again is harmless), because queues may deliver a job more than once (Chapter 22). And never let the processed output trigger the same pipeline again, or it loops forever: keep originals and outputs under different prefixes and only listen to the originals' prefix.

Memory code: "Take the coat now, brush it later."