The Myth of "Single-Threaded Node.js"

"JavaScript is single-threaded." You've heard it a hundred times. Interviews, conference talks, blog posts that open with that exact sentence.

And yeah — your JavaScript code runs on one thread. That part is true.

But Node.js the process is a different story.

The moment you call fs.readFile, do a DNS lookup, you've left JavaScript-land. That work gets handed off somewhere else , a pool of OS threads you never created, probably never thought about, and almost certainly never debugged against.

That's libuv's thread pool. It's been there since the beginning. Most Node.js developers have no idea it exists, which is exactly why certain performance problems are so stubborn to track down.


How many threads is Node.js actually running?

Try it yourself. Spin up a Node.js server and run ps -T -p <PID> on Linux, or top -pid <PID> -l 1 on macOS. You won't see one thread. You'll see somewhere between 5 and 10+, depending on what the process is doing.

The breakdown looks something like this:

Thread

What it's doing

1 × main thread

Running V8, executing your JS, ticking the event loop

4 × libuv workers

The thread pool — handles blocking I/O, crypto, DNS, zlib

V8 GC threads

Background garbage collection. Count varies by V8 version and CPU count.

The 4 libuv workers are the constant. The GC thread count isn't fixed — V8 decides based on the version and how many cores are available. So there's no single magic number. If someone tells you "Node.js uses exactly 7 threads," they're oversimplifying.


The actual architecture

It helps to think of Node.js in layers:

┌─────────────────────────────────┐
│        Your JavaScript Code      │
├─────────────────────────────────┤
│         Node.js Core APIs        │  (fs, crypto, dns, zlib…)
├─────────────────────────────────┤
│           V8 Engine              │  Executes JS on the main thread
│           + GC Threads           │  Background mark/sweep (count varies)
├─────────────────────────────────┤
│             libuv                │  Event loop + thread pool (4 by default)
├─────────────────────────────────┤
│          OS / Kernel             │  Actual I/O, syscalls
└─────────────────────────────────┘

V8 handles your JavaScript. libuv handles the event loop and gives you a thread pool to dump blocking work into. The GC runs in the background so it doesn't freeze your main thread mid-request. Each layer has a job.


libuv and the thread pool

libuv is a C library — the engine underneath Node.js that handles async I/O consistently across Linux, macOS, and Windows. Deno and Julia use it too now, but it was built for Node.js originally.

When Node.js starts, libuv spins up a thread pool with 4 workers. Not based on your CPU count, not something you can change at runtime — just 4, always.

You can feel that limit with a simple test:

javascript

const fs = require('fs');
const start = Date.now();

for (let i = 0; i < 8; i++) {
  fs.readFile('/etc/hosts', () => {
    console.log(`Task ${i + 1} done at +${Date.now() - start}ms`);
  });
}

You'll see two batches in the output. Tasks 1–4 finish around the same time, then tasks 5–8 finish together a bit later. The second group had to wait — all 4 workers were busy.

Set UV_THREADPOOL_SIZE=8 first and all eight finish together. Same work, no waiting.


What's happening with the V8 GC threads

V8's garbage collector does most of its work in the background, on separate threads, so it doesn't freeze your main thread. Two things run concurrently: marking objects as live or dead while your JS executes, and splitting evacuation work across threads when collecting short-lived objects.

You can't configure any of this — V8 decides how many threads to use internally. The only reason it's worth knowing: those threads are why your process shows 6, 7, or 8 threads when you inspect it. People see that and get confused. It's just GC housekeeping.


Not everything hits the thread pool

The thread pool handles a specific category of work — not all async operations:

Operation

Where it runs

fs.*, crypto, zlib

libuv thread pool

dns.lookup()

libuv thread pool — blocks a worker for the whole call

TCP/UDP network I/O

OS kernel directly

dns.resolve()

OS kernel via c-ares, fully async

Timers, process.nextTick, Promises

Main thread

The surprising one is network I/O — TCP connections bypass the thread pool entirely. If your app is mostly HTTP, the pool isn't involved at all.

The dns.lookup() vs dns.resolve() difference is a real footgun. dns.lookup() blocks a pool worker for the entire call. Under high concurrency that adds up fast — it's caused real production latency incidents.


Configuring the pool size

You have one lever: UV_THREADPOOL_SIZE. Set it in the environment, not in code.

bash

UV_THREADPOOL_SIZE=16 node server.js

Bump it if you're running file processing pipelines, auth servers doing bcrypt/pbkdf2, or anything hammering dns.lookup() under load — and only after profiling confirms the pool is actually the bottleneck.

Don't bump it for a typical HTTP service. That traffic bypasses the pool entirely, so it won't help. And more threads aren't free — each one costs ~8MB of stack space on Linux, plus context switching overhead.


What to actually remember

A Node.js process is not single-threaded. The JavaScript runtime is. Those aren't the same thing.

The thread pool defaults to 4 workers. Not 8, not "one per core" — 4. Only touch UV_THREADPOOL_SIZE if a profiler tells you to.

Network I/O bypasses the thread pool entirely. If you're trying to fix HTTP throughput by tweaking pool size, you're looking in the wrong place.

dns.lookup() is a silent pool-blocker. dns.resolve() isn't. Under connection-heavy workloads, that one swap has fixed real production incidents.

Thread pool saturation looks like everything slowing down at once — at some concurrency threshold you can't quite explain. Now you can.