Questions
8 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
08 / 24

Explain the concept of object streams and provide an example use case.

Difficulty: 5/10
objectMode, pipeline, back‑pressure

By default, Node.js streams deal with Buffer or string data, but object streams make it easier to handle structured data, such as JSON objects, arrays, or even complex custom objects.

To create or use an object stream, the objectMode property must be set to when creating a stream. This enables the stream to work with JavaScript objects rather than just bytes or characters.
Example Use Cases
  1. 1

    Data Transformation Pipelines: Converting data formats (e.g., JSON to CSV). Normalizing data (e.g., modifying or restructuring object properties).

  2. 2

    Logging Systems: Streaming log entries as structured objects for storage or analysis

  3. 3

    Database Operations: Streaming objects from a database query and transforming or processing them before writing them to another source.

Scenario Questions

0-2 years experience

  1. 1How would you read a JSON file line by line using an object stream in Node.js?
  2. 2If you set `objectMode: true` on a readable stream, what type of data does it emit compared to the default mode?
  3. 3What happens if you pipe an object‑mode readable stream into a writable stream that expects Buffer data?

2-5 years experience

  1. 1You need to transform a stream of user objects to only include `id` and `email`. How would you implement this using Node.js streams, and what pitfalls might you watch for?
  2. 2During a deployment, the pipeline that processes incoming JSON messages started throwing `ERR_STREAM_WRITE_AFTER_END`. What could cause this in an object‑stream setup?
  3. 3Explain why using `stream.pipeline` is preferable to manually handling `error` events when chaining object streams.

5-8 years experience

  1. 1Design a high‑throughput log‑processing service that consumes JSON logs from a TCP socket, enriches them, and writes to a database. How would you leverage object streams, and what scaling concerns arise?
  2. 2When processing large CSV files as objects, you notice memory usage growing over time. What could be causing a memory leak in your object‑stream pipeline, and how would you mitigate it?
  3. 3Compare using object streams versus reading the whole file into memory for batch processing in terms of back‑pressure and fault tolerance.

8+ years experience

  1. 1Your organization wants to replace a monolithic ETL job that reads/writes JSON files with a streaming architecture across multiple microservices. What architectural changes and cross‑team considerations would you address when introducing object streams as the core data transport?
  2. 2How would you design a versioned schema evolution strategy for object streams that flow between services, ensuring backward compatibility without breaking existing consumers?
  3. 3Discuss the trade‑offs of using Node.js object streams versus a dedicated message broker like Kafka for inter‑service data pipelines at scale.

Follow-up Questions

  • Can you sketch a minimal implementation of that pipeline?
  • What would you monitor in production to ensure the stream stays healthy?
  • How would you test error handling in an object‑mode pipeline?
Share

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