Node.js Concurrency Internals

Parent: JavaScript and Node.js · researched 2026-06-01T01:40:24.084Z· 11 sources · 11 concepts · skill nodejs-concurrency-internals

How Node.js does concurrency on a single main thread: the libuv event loop that

Node.js Concurrency Internals

When to use this reference

When NOT to use this reference

1. The libuv event loop and its phases

The poll phase decides how long the process sleeps

libuv is what makes I/O async

2. Microtasks: process.nextTick and the Promise queue

nextTick / microtask starvation

setTimeout(…, 0) vs setImmediate

3. The libuv thread pool

4. Don't block the event loop (or the pool)

5. Streams and backpressure

highWaterMark and the write() / drain contract

Prefer pipeline() over pipe()

Custom stream rules

Web Streams API (WHATWG) & Node interop (Readable.toWeb/fromWeb, stream/consumers)

Construction (underlying source / sink / transformer)

Backpressure: the demand/pull model (vs classic write()/drain)

Default vs BYOB (byte) readers

Bridging classic ↔ Web (toWeb / fromWeb)

Consuming either stream world: stream/consumers & stream/promises

6. Three ways to escape the single thread

7. worker_threads

8. cluster

9. child_process

References

Children

Frontier under this node: Don't block the event loop (sync APIs, ReDoS, partitioning vs offloading, event-loop lag), Microtask ordering (process.nextTick queue + Promise microtask queue, starvation), Stream types and custom streams (Readable/Writable/Duplex/Transform, push/write rules, cork/uncork), Streams and backpressure (highWaterMark, write()/false, drain, pipe vs pipeline), Web Streams API (WHATWG) & Node interop (ReadableStream/WritableStream/TransformStream, Readable.toWeb/fromWeb, stream/consumers), child_process (spawn/exec/execFile/fork, shell command-injection, maxBuffer, IPC, detached/unref), cluster (SCHED_RR vs SCHED_NONE, shared server ports, worker lifecycle, built on child_process.fork), libuv event loop phases (timers, pending callbacks, idle/prepare, poll, check, close), libuv thread pool (UV_THREADPOOL_SIZE 4->1024; fs/dns.lookup/crypto/zlib), setTimeout(0) vs setImmediate ordering, worker_threads (V8 isolates, structured clone, transferList, SharedArrayBuffer/Atomics, MessageChannel)

← the whole tree · 3D view· how to read this page