Node.js › Event Loop & Non-blocking IO
What is the difference between how Node.js handles I/O-bound concurrency versus CPU-bound work, and why does this distinction shape Node.js's ideal use cases?
AdvancedAnswer
I/O-bound work (network requests, file reads, database queries) spends most of its time waiting on external systems rather than computing -- Node.js's non-blocking, single-threaded event loop model handles this extremely efficiently, since the thread is never actually blocked waiting, just handling many operations' completions as they arrive. CPU-bound work (image processing, complex calculations, cryptographic operations) genuinely occupies the CPU for the entire duration -- since Node.js's main thread is single-threaded, one CPU-bound task blocks everything else, making Node.js's default model a poor fit for CPU-heavy workloads unless that work is explicitly offloaded to worker threads or separate processes.
// I/O-bound: Node.js's model shines here -- handles many concurrently with one thread
app.get('/user/:id', async (req, res) => res.json(await db.users.findById(req.params.id)));
// CPU-bound: blocks everything else on the main thread if done directly
app.get('/process-image', (req, res) => res.json(applyComplexImageFilter(req.body.image))); // problematicReal-world example A team choosing Node.js for their new API correctly identifies it as an excellent fit given the API is almost entirely I/O-bound (database queries, calls to other services), while explicitly planning to offload their one genuinely CPU-heavy feature (report generation) to a separate worker-thread pool from the start.