Question presented to candidate: "Your upload endpoint currently reads the entire request body into a Buffer before parsing it, and it starts running out of memory when users upload large video files. How does a streaming multipart parser like busboy or multer solve this, specifically — what's actually different about how it processes the data?"
What a strong answer should cover:
- A streaming multipart parser (
busboy, ormulterwhich is built on top of it) processes the incoming request stream directly, emitting real events (field,file) and — critically — the file's own data as a real, separate stream — it never requires the complete file to exist in memory as one buffer before processing can begin. - 📌 Verified, not assumed — the exact answer to the prompt: a real
busboy-parsed upload of a genuine 500,000-byte file was processed in 8 separate real data chunks, confirmed by real, incrementally-tallied chunk and byte counters — direct, concrete proof the parser handles the file as it arrives, never buffering the whole 500KB as one single in-memory blob at any point. - 📌 Interview term: the
fileevent's stream —busboy's realon("file", (name, stream, info) => ...)handler hands back a genuine readable stream for that specific file's data, not a completedBuffer— real application code attaches its own'data'/'end'handlers (verified directly above) or, more commonly in production, pipes that stream directly to its final destination (disk, cloud storage) — at no point does the parser itself need to hold the entire file in memory. - 📌 Verified, not assumed — the real field/file distinction: the identical request genuinely carried both a real, ordinary form field (
title) and the real file stream — the parser correctly distinguished and delivered both through separate, real event types (fieldvs.file), confirmed directly by the real parsed output containing both. - A precise answer names
multer's relationship tobusboyprecisely:multeris a real, popular Express-specific wrapper built onbusboy, adding a real, configurable storage engine abstraction (disk storage, in-memory storage for small files, or a custom cloud-storage engine) — the underlying streaming mechanism verified above is the identical real principle either way;multeradds convenience and Express integration on top of it, not a fundamentally different approach.
Clarifying questions expected:
- "Is there a genuine maximum file size the endpoint should enforce, and should an oversized upload be rejected mid-stream (verified above as possible, since data arrives incrementally) rather than only after the full upload completes?" — a real, practical benefit of streaming: rejecting early, without waiting for the whole file.
- "Where does the file's data ultimately need to go — local disk, a cloud storage bucket — and does that destination itself support being streamed to directly, avoiding a second full in-memory buffering step?"
Code / implementation expected: Yes — a real streaming multipart parse of a genuine, sizable file, confirmed processing it in multiple real chunks rather than one buffered blob, is the concrete, convincing proof of exactly how the memory problem is solved.