Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →
TOPIC 1 OF 6 · 3 MIN READ

Node.js Architecture: V8, libuv and Non-Blocking I/O

Node.js runs JavaScript on one main thread, yet one process can serve thousands of connections. The reason is its architecture: the V8 engine runs your code, and libuv hands slow I/O to the operating system and a small thread pool, then calls you back when it is done.

What you will learn

  • Name the parts of Node.js: V8, libuv, bindings and the core modules
  • Explain why Node.js is single-threaded but not single-threaded underneath
  • Know which work goes to the libuv thread pool
  • Explain when Node.js is a good or bad fit

Key concepts

V8

Google's JavaScript engine. It compiles JavaScript to machine code with a JIT compiler and manages the heap and garbage collection.

libuv

A C library that provides the event loop and async I/O. Network sockets use the OS's own async APIs (epoll, kqueue, IOCP). File system, DNS lookup, crypto and zlib work runs on the libuv thread pool (4 threads by default, set with UV_THREADPOOL_SIZE).

Non-blocking I/O

Instead of waiting for a database reply, Node.js registers a callback and moves on to other requests. When the reply arrives, the callback is queued and run on the main thread.

Blocking the event loop

Any long synchronous work on the main thread (a huge JSON.parse, a heavy loop, fs.readFileSync, a bad regex) stops every other request until it finishes.

Step by step

One request, step by step

  • A request arrives on a socket; libuv sees it through epoll and queues the callback
  • The main thread runs your handler until it hits await db.query()
  • The query is sent; the handler yields; the loop serves other requests
  • The database reply arrives; the continuation is queued and finishes the response

Good and bad fits

Node.js shines at I/O-heavy work: APIs, gateways, real-time apps, BFFs. CPU-heavy work (video encoding, big image processing, ML inference) blocks the loop; move it to worker threads, a queue worker or another language.

Examples

Blocking vs non-blocking

import { readFile } from 'node:fs/promises'
import { readFileSync } from 'node:fs'

// Bad in a request handler: every other request waits
app.get('/bad', (req, res) => res.send(readFileSync('big.json')))

// Good: the read runs on the libuv pool, the loop stays free
app.get('/good', async (req, res) => res.send(await readFile('big.json')))

Practise it

Try these without looking back. If you can explain each one out loud, you are ready for this question.

  • Explain why crypto.pbkdf2 is async but still limited by the thread pool size.
  • Write a route with a 2-second busy loop and measure how it slows a second route.
  • Explain why 4 slow fs calls can delay a 5th fs call but not a network call.

Interview questions

What interviewers ask next on this topic. Answer out loud first, then open the model answer.

Is Node.js single-threaded?

Your JavaScript runs on one main thread. Node.js itself uses more threads: the libuv thread pool for file system, DNS, crypto and zlib, plus V8 threads for garbage collection and compilation. You can add your own with worker_threads.

How does Node.js handle 10,000 concurrent connections?

Each connection is just a socket registered with the OS event notification system. No thread is created per connection, so memory stays low. The loop only does work when a socket has data.

Summary

V8 runs JavaScript on one thread, libuv provides the event loop, OS-level async networking and a thread pool for file and crypto work. Keep the main thread free of long synchronous work and Node.js scales very well for I/O.

Stuck on this one? Talk to Sumit.

Keys: F focus mode · ← → previous / next topic · Esc leave focus