Backpressure prevents producers from overwhelming consumers. Writable streams signal whether more data can be accepted without unbounded buffering.
Before you start
You should know JavaScript promises, asynchronous errors and the distinction between a process and a request. When following a server example, identify the resource owner and the point where work completes. Try experiments locally with bounded input instead of assuming production traffic behaves like a single request.
The practical goal is to reason through this situation: When write returns false, wait for drain before continuing production. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Identify the slow consumer
A network client may accept bytes more slowly than an export can produce them.
Step 2: Honor writable signals
When write returns false, pause production until drain or failure instead of appending indefinitely.
Step 3: Propagate termination
Stop the producer on destination failure or disconnect; completion needs error handling across the stream chain.
Worked scenario
When write returns false, wait for drain before continuing production.
A report source can generate 100 MB quickly while the client downloads slowly. Ignoring backpressure retains queued chunks in memory. A pipeline coordinates flow, while a custom producer must explicitly obey the destination’s capacity signal. A disconnected client should not leave the report generator doing useless work.
Common mistake
Ignoring the signal can increase memory dramatically under slow clients.
Verify the behavior
Use a deliberately slow writable and a failing destination. Check bounded memory and upstream cleanup in both cases.
Interview exercise
Stream a large export safely.
Answer and reasoning
Use pipeline or a backpressure-aware producer, handle errors and stop upstream work when the consumer disconnects.
Continue learning
Compare the scenario with the Node.js interview questions and test your understanding with the Node.js MCQs. For terminology and implementation details, consult the reference material.