The Standard Chunked Upload Recipe Fails on Real Networks — Here's the Fix
File upload is a solved problem in demos but a persistent source of production incidents. The gap between the interview answer and a working implementation is three concrete engineering decisions — concurrency control, memory discipline, and state persistence — that directly determine whether an upload survives a train tunnel or a coffee-shop network.
Interview-ready chunked uploads — slice with `Blob.slice`, fire with `Promise.all`, merge on the backend — break down the moment they hit a real network. Browsers cap per-domain connections to six, so 100 simultaneous requests queue up and time out. A single failed chunk rejects the entire batch, discarding already-uploaded work. The fix is a native async queue that caps concurrency at four and pushes failed chunks to the back of the line for silent retry.
Real devices expose deeper traps. Converting every `Blob` to an `ArrayBuffer` before upload can OOM-crash a tab on a 5 GB file; `File.slice()` returns a lightweight pointer, and data should stay as a reference until it enters `FormData`. Hashing multi-gigabyte files on the main thread freezes the UI for tens of seconds — sampling the head, tail, and a few middle segments inside a Web Worker drops that to hundreds of milliseconds. Mobile browsers kill background tabs, so each completed chunk must write its state into IndexedDB or localStorage. On reload, the uploader reads the persisted map, skips finished chunks, and resumes without losing progress.
The standard interview answer for large-file upload is so widely taught that it has become a liability — it describes a demo that works only on localhost with a perfect connection.
Production upload logic is less about clever algorithms and more about respecting three hard physical limits: the browser's connection pool, the device's memory ceiling, and the network's unreliability.
Sampling-based file hashing is an under-discussed technique that trades a tiny collision risk for a 100x speedup, making it practical for browser-side integrity checks on large files.