skip to content

Why must a wedding-photography app keep its upload queue on disk, and what should each queued photo or video record?

level: juniorimportance: must knowfreq 46%

answer

  1. the process can end at any moment
  2. memory is gone after a kill
  3. a reference to the file, not bytes
  4. waiting, uploading, committed, failed
  5. the server's upload address and offset

basics

~20 s

Because the OS may end a backgrounded app at any time, taking its memory with it. Each entry records the file's path, size and content hash, its state (waiting, uploading, committed, failed) and the server's upload address.

solid answer

~50 s

A photographer queues 600 photos and three long clips, locks the phone and keeps shooting; hours later the app may have been suspended, ended by the system to free memory, or swiped away. An in-memory list dies with the process, so the next launch could not tell which files went up. Each entry in the local database holds a **reference to the file** (never its bytes), its size and a content hash, the target gallery and priority, a state — `waiting`, `uploading`, `committed`, `failed` — the server's upload address once one exists, the last offset the server reported, and the attempt count and last error. An entry becomes `committed` only when the server confirms it stored the whole file; then any temporary copy is deleted. On relaunch the app reads the queue, skips committed entries and resumes the rest.

code

json · 15 lines
json
{
  "id": "u-7f3c2a",
  "fileRef": "library:photo-4821",
  "bytes": 24117248,
  "contentHash": "sha256:9b1e...c04a",
  "galleryId": "g-2026-06-14-hartley",
  "priority": 1,
  "state": "uploading",
  "uploadUrl": "https://uploads.example.com/u/5d21",
  "urlExpiresAt": "2026-06-14T19:40:00Z",
  "serverOffset": 16777216,
  "attempts": 2,
  "lastError": "network-lost",
  "updatedAt": "2026-06-14T18:52:11Z"
}

go deeper

for a junior

Recall that a backgrounded app can be ended without warning and loses its memory, so the queue and each file's state must already be on disk when that happens.

for a middle

Explain the entry's fields and its states — waiting, uploading, committed, failed — and why committed waits for the server's confirmation rather than the last byte sent.

for a senior

Show the relaunch path: reconcile stored states with the OS and the server, detect missing or changed source files, and keep temporary copies until the server commits.

for a principal

Weigh one shared transfer queue for every media feature against per-feature queues: common priorities, storage cleanup and progress UI versus coupling and ownership across teams.

## Why the queue cannot live in memory A wedding photographer queues **600 full-resolution photos and three long clips**, locks the phone and goes back to shooting. Over the next few hours the app moves through states it does not control: - **Suspended** — the app's code stops running in the background; memory is intact, but nothing in it advances. - **Ended by the system** — the OS reclaims memory from a backgrounded app without warning, and with no guaranteed callback; every in-memory structure is gone. - **Swiped away by the user** — the photographer clears recent apps to save battery; the app is closed, and what happens to transfers already handed to the OS depends on the platform. - **Phone restarted** — the battery dies during the speeches. A queue held only in memory survives none of the last three. The next launch would see a gallery with 214 photos in it and no record of which 386 are missing, which are half-sent and which clip was 80 % done. Rescanning the photo library does not help: the library knows what was shot, not what reached the server. So the queue is a table in the app's **local database**, written when the photographer taps *Upload* — not deferred to the moment the app goes to the background, when the time the OS allows is short, and a crash or a flat battery before then would lose everything. ## What one entry records | Field | Why it is there | |---|---| | `id` | a stable identifier the app minted, used to match OS transfer tasks and server uploads back to this row | | `fileRef` | a path or photo-library identifier for the file on disk — never the bytes themselves | | `bytes`, `contentHash` | to notice a file that changed or disappeared, and to avoid queueing the same photo twice | | `galleryId`, `priority` | where the file goes and in what order (the couple's favourites first) | | `state` | `waiting`, `preparing`, `uploading`, `committed` or `failed` | | `uploadUrl`, `urlExpiresAt`, `serverOffset` | the server-side upload this file is resuming, when its address stops being valid, and the last offset the server reported | | `attempts`, `lastError`, `updatedAt` | for retry decisions and for an honest message to the photographer | The bytes stay where they are. A 2 GB clip copied into a database row would bloat the store, slow its queries and any backup of it, and duplicate a file that already exists. If the app made a compressed copy, that copy lives in the app's own folder and the entry points at it. ## The states, and what moves an entry between them 1. **waiting** — queued, nothing sent yet. 2. **preparing** — the app is compressing or copying the file (only when this upload is re-encoded). 3. **uploading** — a server-side upload exists; bytes are moving or paused. The entry holds its address and last known offset. 4. **committed** — the server's final response confirmed that the whole file was received and accepted. Only now is any temporary copy deleted. 5. **failed** — the source file vanished, or the server refused the file for a reason that retrying cannot fix; the reason is stored and shown. The transition that matters most is the one into `committed`. Sending the last byte is not the same as the server keeping the file: the final response can be lost in a tunnel. An entry left in `uploading` costs one question to the server on the next attempt, which then reports the upload complete; an entry marked `committed` too early loses a photo silently. ## The relaunch path When the app starts — because the photographer opened it, or because the OS woke it to report a finished transfer — it: 1. reads every entry that is not `committed`; 2. checks that each `fileRef` still points at a readable file of the recorded size, and marks the rest `failed` with a reason the photographer can act on; 3. matches entries in `uploading` against transfers the OS still reports, and for the rest asks the server how much it holds; 4. rebuilds the progress it shows from these states, not from whatever the screen said last. ## Not the same as an outbox of small writes A queue of pending record edits — a comment, a rename — replays small request bodies in order, and its rules on writing the change and the entry in one transaction belong to that subject. This queue differs in kind: the payload is a **large file referenced by path**, progress is measured in **bytes the server holds**, the transfer may run inside an OS service rather than the app, and files can go in whatever order the product prefers. Give it its own table and its own states. ## Picking the same photo twice A photo picked from two albums should go up once. At enqueue time the app hashes the **original** file's bytes, streaming it off the main thread, and looks for an entry with the same hash for the same gallery; if one exists, the second pick links to it instead of adding a row. Hashing the original matters: two compression runs need not produce byte-identical output, so a hash of the compressed copy could miss the duplicate. Deduplication across the server's whole store is a server-side subject.

  • Why store a reference to the file rather than copying a 2 GB clip's bytes into the database?
    The file already exists on disk; a copy in a row doubles the space, bloats the store and slows its queries and any backup of it. Keep a path or photo-library identifier plus the size and hash, and check on relaunch that the file is still there and unchanged. If the photographer deleted it, the entry becomes `failed` with a clear reason instead of retrying forever.
  • The photographer selects the same photo from two albums; how does the queue avoid uploading it twice?
    At enqueue, hash the original file's bytes off the main thread and look for an entry with the same hash for the same gallery; if one exists, link to it instead of adding a row. Hash the original, not a compressed copy, because two compression runs need not produce identical bytes. Store-wide deduplication is the server's subject; this is the client's own check.
  • When is an entry safe to mark committed?
    Only when the server's final response confirms the whole file was received and accepted — not when the last byte leaves the phone. If that response is lost, the entry stays `uploading`; the next attempt asks the server for the upload's state, learns it is complete and marks it committed then.

  • An in-memory list is fine because uploads finish before the app closes.
  • Store each video's bytes in the database row so nothing can go missing.
  • A file is uploaded once its last byte has left the phone.
  • After a relaunch the app can tell what was uploaded by rescanning the photo library.
  • Saving the queue can safely wait until the app is about to go to the background.