Questions
13 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
13 / 24

What is the purpose of the `highWaterMark` option when creating a readable stream?

Difficulty: 5/10
stream buffering, backpressure, performance tuning
  1. 1

    The highWaterMark option determines the size (in bytes) of the internal buffer used by a readable stream.

  2. 2

    When the buffer is full, the readable stream will stop reading data from its source until the buffer has been drained.

  3. 3

    It helps control backpressure by specifying the maximum amount of data that can be buffered before pausing the source.

Scenario Questions

0-2 years experience

  1. 1You need to read a large file line by line using a readable stream. How would you choose the highWaterMark, and what would happen if you set it too low?
  2. 2If you create a readable stream without specifying highWaterMark, what default behavior should you expect when data arrives faster than you consume it?

2-5 years experience

  1. 1Your service streams JSON objects from a database to HTTP clients and you start seeing backpressure warnings. How would you adjust highWaterMark to mitigate this, and what trade‑offs are you making?
  2. 2During a load test, the memory usage of a Node.js process spikes while streaming video. Explain how highWaterMark could be contributing and how you'd debug it.

5-8 years experience

  1. 1Design a streaming pipeline that ingests data from a TCP socket, transforms it, and writes to the file system. Discuss how you would set highWaterMark at each stage to balance throughput and memory under bursty traffic.
  2. 2You need to support both low‑latency real‑time analytics and high‑throughput batch processing in the same service. How would you use highWaterMark differently for each path, and what impact does it have on backpressure propagation?

8+ years experience

  1. 1Your organization is migrating a legacy monolithic file‑processing service to a microservices architecture that uses Node.js streams across network boundaries. What architectural considerations around highWaterMark would you raise to ensure compatibility, observability, and future scalability?
  2. 2When defining a shared streaming library used by multiple teams, how would you expose highWaterMark configuration to balance default safety with the ability for power users to tune performance, and what governance policies would you put in place?

Follow-up Questions

  • How does Node.js decide when to pause or resume a readable stream based on highWaterMark?
  • What happens if the consumer never reads from the stream?
  • Does highWaterMark behave differently when objectMode is true?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.