NODEJS Contents

Concurrency Model: Non-blocking I/O Explained

Understand how Node.js handles concurrency using non-blocking I/O instead of multi-threaded request handling.

On this page

Concurrency vs Parallelism

Node.js achieves concurrency through asynchronous I/O. It does not create one thread per request.

Non-Blocking I/O

When waiting for disk or network, Node delegates work and continues processing other events.

Worker Threads

For CPU-bound tasks, Node provides worker threads to achieve parallel execution.

Example Concept

import { Worker } from 'worker_threads';

Production Strategy

  • Use async I/O for scalability.
  • Offload CPU tasks.
  • Monitor event loop lag.