Questions
14 of 24
1What are streams?
2List elementary stream types.
3What are advantages of streams.
4Create a readable stream
5How can you create a custom Transform stream in Node.js?
6What is the `end` event in a readable stream, and how is it different from the `finish` event in a writable stream?
7How can you handle errors in Node.js streams?
8Explain the concept of object streams and provide an example use case.
9Explain the difference between `ObjectMode` and `Buffer` mode in a readable stream.
10Explain the difference between a flowing and a non-flowing readable stream.
11What is the difference between the `data` event and the `readable` event in a readable stream?
12How can you handle cleanup operations when working with streams?
13What is the purpose of the `highWaterMark` option when creating a readable stream?
14What is backpressure in Node.js streams, and how can you handle it?
15What is the pause() method used for in a readable stream, and how can you resume data flow?
16What is the purpose of the `stream.finished()` utility in Node.js?
17How do you handle stream errors when working with async/await in Node.js?
18How can you handle memory usage when dealing with large files in Node.js streams?
19Explain the concept of piping in Node.js streams.
20What is the purpose of pipeThrough function
21What is the purpose of the `unpipe()` method in Node.js streams, and how does it work?
22Explain the difference between `pipe()` and `on('data')` when working with streams.
23What is the purpose of the `stream.pipeline()` function in Node.js?
24write code of a stream to read a local file in node js
14 / 24

What is backpressure in Node.js streams, and how can you handle it?

  1. 1

    Backpressure occurs when the writable stream cannot handle data as fast as it's being produced by the readable stream.

  2. 2

    To handle it, you can use flow control mechanisms like pause() and resume() methods or set the highWaterMark option when creating a readable stream.

Difficulty: 6/10
Topics: flow control, readable/writable streams, pipeline debugging

Scenario Questions

0-2 years experience
  1. 1

    You need to pipe a large file read stream into an HTTP response. How would you make sure the server doesn’t run out of memory?

  2. 2

    If the writable stream’s write() method returns false, what does that tell you and what should you do next?

  3. 3

    What can happen if you ignore backpressure when reading from a fast source and writing to a slow destination?

2-5 years experience
  1. 1

    During a data migration you built a pipeline with Transform streams, but it stalls under load. Walk me through how you’d debug the backpressure issue.

  2. 2

    After adding a compression Transform stream to a file‑upload endpoint, requests started timing out. How would you modify the code to handle backpressure correctly?

  3. 3

    A readable stream is emitting data faster than the downstream consumer can process. How would you throttle or buffer to keep the pipeline stable?

5-8 years experience
  1. 1

    Design a high‑throughput logging service that writes logs to disk using streams. How would you architect backpressure handling to avoid dropping logs during traffic spikes?

  2. 2

    In a microservice that streams video chunks to many clients, how would you balance backpressure across concurrent streams while keeping latency low?

  3. 3

    When integrating a third‑party API that provides a readable stream, you need to merge it with other streams. What strategies would you use to propagate backpressure correctly across the whole chain?

8+ years experience
  1. 1

    Our legacy monolith uses custom event emitters for data flow, and we plan to migrate to Node.js streams for better flow control. How would you approach the migration to ensure backpressure semantics are preserved across services?

  2. 2

    Several teams share a streaming library that many services depend on. What guidelines and abstractions would you establish to make backpressure handling consistent and future‑proof?

  3. 3

    We expect to scale the platform to handle billions of events per day. How would you redesign the streaming infrastructure to handle backpressure at the cluster level, considering load balancing and fault tolerance?

Follow-up Questions

  • Can you sketch a short code example that reacts to a false write() return?
  • What runtime metrics would you watch to spot backpressure issues in production?
  • How does adjusting highWaterMark affect when backpressure is applied?