Thread-per-Request Scalability Limits
Traditional web servers (like Apache HTTP Server or IIS) handle concurrent requests by assigning each connections to a separate system thread. When the thread requests a database query or filesystem action, it blocks—sitting idle until the data returns.
With millions of users, this model consumes massive system memory because thread stack allocations are expensive.
Node.js (released by Ryan Dahl in late 2009) offers a completely different design: single-threaded, non-blocking asynchronous I/O.
Google's V8 Engine and the Event Loop
Node.js compiles JavaScript directly into machine code using Google Chrome's fast V8 engine.
Key design mechanics of Node.js:
- ◆Single Thread: Only one process executes application JavaScript.
- ◆Asynchronous Callback Pattern: When an I/O operation (database read, network request) is initiated, Node.js delegates the action to system threads and continues executing application code.
- ◆Event Loop: When the I/O completes, the callback is pushed to a queue for execution on the main thread.
// A simple HTTP server configuration in 2010 Node.js
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello from Node.js Event Loop!
');
}).listen(8080, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8080/');Non-Blocking I/O
Instead of blocking execution, asynchronous operations receive callback functions:
const fs = require('fs');
fs.readFile('/var/log/system.log', 'utf8', (err, data) => {
if (err) throw err;
console.log("File read successfully.");
});When to Adopt Node.js?
Node.js is highly efficient for I/O-heavy applications (such as real-time messaging, streaming services, and proxy APIs). It is not suitable for CPU-heavy tasks (like image processing or scientific computing), as these block the main thread and freeze the entire server.