A readable stream is typically used to handle input, such as reading from a file or generating data programmatically. For example:
Readable streams can be consumed in three ways: using event listeners, the method, or async iterators. Here are examples:
Scenario Questions
0-2 years experience
1How would you implement a simple readable stream that emits the numbers 1 through 10?
2If you pipe that readable stream into a writable file stream and the file system is slower than the data generation, what does Node do?
2-5 years experience
1We need to process a large CSV file line‑by‑line without loading it all into memory. How would you set up a readable stream for this, and which options would you tune?
2During a recent deployment the stream started throwing 'ERR_STREAM_DESTROYED' errors. What could cause that, and how would you go about debugging it?
5-8 years experience
1Our service reads HTTP request bodies using a custom readable stream that throttles data based on downstream processing speed. How would you design backpressure handling, and what trade‑offs does it introduce?
2We want to replace a legacy event‑emitter pipeline with a Node.js readable stream to reduce memory usage. What architectural changes and edge cases must you consider?
3If the stream must support both object mode and binary mode depending on runtime configuration, how would you implement that without breaking existing consumers?
8+ years experience
1At a platform level we plan to stitch together multiple microservices via Node.js streams for a data ingestion platform. How would you design stream boundaries, error propagation, and versioning to ensure long‑term maintainability?
2Our monolith currently writes logs synchronously. We want to migrate to an async, back‑pressured streaming logger used across all services. What migration strategy would you propose and how would you mitigate risk?
3Considering cross‑team usage, how would you expose a reusable readable‑stream library that handles backpressure, cancellation, and monitoring while keeping the API stable for future Node versions?
Follow-up Questions
What would you change if the data source was asynchronous, like a database query?
How does Node decide when to pause or resume a readable stream?
Can you describe how you would test that your stream correctly handles backpressure?