Node.js Developer interview question · Most asked
What does libuv's thread pool do, and which operations use it?
Summary
libuv maintains a thread pool (default 4 threads, configurable with UV_THREADPOOL_SIZE up to 1024) for operations that lack non-blocking OS APIs: most fs operations, dns.lookup, some crypto functions (pbkdf2, scrypt, randomBytes async) and zlib compression.
Longer Answer
Network I/O (TCP/HTTP sockets) doesn't use the pool; it uses OS event notification. If many slow fs or crypto calls saturate the 4 threads, other pool tasks queue up, causing surprising latency, e.g. DNS lookups delayed by bcrypt hashing. Increase the pool size or move heavy work elsewhere.
Key Points
- Default 4 threads (
UV_THREADPOOL_SIZE) - fs, dns.lookup, crypto, zlib
- Network sockets don't use it
- Saturation causes hidden latency
More most-asked Node.js Developer questions
- What is the difference between `process.nextTick`, Promise microtasks, `setImmediate` and `setTimeout(fn, 0)`?
- What are streams in Node.js and what is backpressure?
- Walk through how an Express app handles a request, including errors from async handlers.
- Explain the phases of the Node.js event loop.
- How has asynchronous code evolved in Node.js: callbacks, Promises and async/await?
- What is Node.js and why is it well suited to I/O-heavy servers?
- Why is CPU-bound work a problem in Node.js and how do you handle it?
- What are the differences between CommonJS and ES modules in Node.js?