mediumLow-Level Design

How does the thread pool work in Node.js?

515 views
01

Understand the problem

Describe how Node.js executes blocking operations that cannot be handled by the single-threaded event loop.

libuvmultithreadingevent-loop
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Saturating the pool
import crypto from 'node:crypto';

console.time('hash');
// 4 finish together; the 5th starts only after a thread frees up.
for (let i = 0; i < 5; i++) {
  crypto.pbkdf2('pw', 'salt', 1e6, 64, 'sha512', () => {
    console.timeLog('hash', 'done', i);
  });
}
// Run with UV_THREADPOOL_SIZE=5 to let all five run in parallel.
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.