Node.js runtime · Concept
Is Node.js single-threaded?
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
People say Node.js is single-threaded. Then how does one Node process serve ten thousand open connections at the same time?
Then
Follow-ups the interviewer asks next
- Which parts of Node really are multi-threaded?
- Walk me through what happens from the moment a request's bytes arrive to the moment your handler runs.
- Name the event loop phases. Where do promise callbacks and
process.nextTickrun? - So what kind of work is Node bad at, and what do you do about it?
- Have you seen a Node service struggle because of this? What was it?
The answer
What a strong answer covers
- Your JavaScript runs on one main thread with one call stack. Node itself is not single-threaded: V8 has helper threads (garbage collection, compiler) and libuv has a thread pool (4 threads by default).
- Network I/O does not use those threads. libuv asks the OS to watch thousands of sockets at once (epoll on Linux, kqueue on macOS, IOCP on Windows) and runs a callback when a socket is ready. Waiting costs almost nothing.
- One turn of the loop: timers → pending callbacks → poll (new I/O; most request handlers start here) → check (
setImmediate) → close callbacks. After each callback, Node empties thenextTickqueue, then the promise microtask queue. - Good at I/O-bound work (APIs, proxies, real-time). Bad at long CPU work (huge JSON, image resizing, sync crypto), because while one callback runs, no other request moves.
- For CPU work: worker threads, a separate service or queue, or more processes (cluster or more pods).
The red pen
Common traps
Avoid:"Node is multi-threaded because of libuv"; "Node can only handle one request at a time"; saying async/await moves work to another thread.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.