Questions
9 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
09 / 24

Explain the difference between `ObjectMode` and `Buffer` mode in a readable stream.

Difficulty: 6/10
streams, backpressure, memory-management
  1. 1

    ObjectMode`: In this mode, a readable stream emits JavaScript objects, making it suitable for transmitting structured data. It's often used when dealing with JSON or other non-binary data formats.

  2. 2

    Buffer` mode: In this mode, a readable stream emits binary data in the form of Node.js Buffers. It's commonly used for reading and writing binary data like files. It is the default mode

Scenario Questions

0-2 years experience

  1. 1We have a readable stream reading JSON lines from a file. If we set `objectMode: true`, what does our `data` event handler actually receive compared to when it's set to `false`? How does this change how we parse the incoming data?
  2. 2You're writing a stream to process user records from a database. You notice that when you push a plain JavaScript object into your readable stream, it throws an error saying 'Invalid non-string/buffer chunk'. What's causing this, and how do you fix it?

2-5 years experience

  1. 1We are processing a massive CSV file. The developer wrote a custom transform stream that parses rows into JS objects, but they forgot to set `objectMode: true` on the downstream writable stream. What kind of runtime errors or silent failures should we expect to see here, and how do we safely bridge the binary-to-object boundary?
  2. 2We have an API that streams database rows to a client. We enabled `objectMode: true` on our query stream, but now we're seeing memory spikes under heavy load. How does the `highWaterMark` setting change when you switch to object mode, and how might that explain the memory leak?

5-8 years experience

  1. 1We're building an ETL pipeline in Node.js that processes millions of complex nested objects per minute. We're debating between keeping everything in `objectMode` streams versus serializing to NDJSON (newline-delimited JSON) buffers at each step. What are the CPU, memory, and garbage collection tradeoffs of these two approaches?
  2. 2You are designing a custom stream-based rate limiter for an internal event-processing engine. If the upstream is an object-mode stream emitting heavy payload objects, how would you design the backpressure mechanism to ensure we don't run out of memory, given that `highWaterMark` only counts the number of objects rather than their actual byte size?

8+ years experience

  1. 1Our core platform relies on a legacy event-streaming library built on Node.js object-mode streams. As our event sizes have grown from small metadata payloads to large, multi-megabyte documents, we're hitting severe V8 heap fragmentation and GC pauses. How would you architect a migration path away from object-mode streams to a buffer-based or zero-copy architecture without breaking downstream consumer teams?
  2. 2We are designing an enterprise-grade plugin architecture where third-party developers can pipe their own custom streams into our data ingestion pipeline. How do we enforce strict memory limits and backpressure safety when we don't know if a plugin will return an object-mode stream or a raw buffer stream? What defensive patterns would you establish at the integration boundaries?

Follow-up Questions

  • How does the default highWaterMark value change when you toggle objectMode on?
  • If an object-mode stream is pushing massive 10MB objects, how does the default backpressure limit of 16 objects protect or fail to protect our system memory?
  • What is the performance overhead of serializing objects to buffers versus passing them directly in objectMode?
Share

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