Node.js runtime
Event loop, blocking the loop, streams, backpressure, worker threads. Why one slow JSON.parse can stall every request in flight.
The mental model
Node.js is one chef in a kitchen who never waits at the stove. There is a single main thread executing your JavaScript, but it refuses to stand idle. When it starts a slow operation — reading a file, querying a database, calling an API — it hands that work to the kitchen staff (the operating system and a thread pool), writes down "call me when it's ready", and immediately moves to the next order. When a result comes back, its callback is queued and the chef picks it up. This is the event loop: one thread, never blocking, orchestrating thousands of in-flight operations.
The analogy that sticks: a **short-order cook versus a line of cooks**. A traditional threaded server assigns one cook (thread) per customer (request); 10,000 customers means 10,000 cooks and the memory and context-switching cost of all of them. Node uses one cook who takes an order, puts the steak on the grill (I/O, handled elsewhere), and turns to the next customer while it sizzles. This is spectacularly efficient for I/O-bound work — most web servers, which spend their time waiting on databases and networks. It is *terrible* the moment the cook has to do long math at the counter, because while they compute, every other customer waits. **One slow JSON.parse of a huge payload can stall every request in flight**, because there is only one cook.
Why this design exists: web servers are overwhelmingly I/O-bound — they wait far more than they compute. The thread-per-request model spends most of its resources on threads that are blocked doing nothing. Node's single-threaded, non-blocking model lets one process handle enormous concurrency cheaply, as long as you never block the one thread. Understanding what blocks it — and how to move CPU-heavy work off it — is the whole game.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision