Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Which Node.js feature is lighter, runs inside the same process, and allows you to share memory directly between parallel threads without having to serialize data into JSON?
💻 Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Worker Threads and Child Processes pipeline. Include the setup and basic execution steps.
You are reviewing a Node Worker Threads and Child Processes pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Spawning a brand new Worker Thread (or Child Process) on every single incoming HTTP request
// Wrong: creates and tears down a new thread for every request
app.get('/resize', (req, res) => {
const worker = new Worker('./resize.js', { workerData: req.body });
worker.on('message', (result) => res.json(result));
});
// Correct: reuse a warm pool of threads
const pool = new Piscina({ filename: './resize.js' });
app.get('/resize', async (req, res) => {
res.json(await pool.run(req.body));
});The Solution //
Booting a Worker Thread has real overhead (creating a new V8 isolate, allocating memory) — doing it per-request under real traffic means most of your CPU savings are eaten by constant thread creation/teardown, and you can exhaust system resources under load. Use a thread pool library like piscina that keeps a fixed number of warm threads and reuses them across requests.
The Error //
Reaching for child_process when worker_threads would be lighter and simpler for pure JavaScript computation
// Heavier than necessary for pure JS math
const { spawn } = require('child_process');
spawn('node', ['heavy-math.js']);
// Lighter and purpose-built for JS computation
const { Worker } = require('worker_threads');
new Worker('./heavy-math.js');The Solution //
child_process.spawn() launches an entirely separate OS process with its own V8 instance, which is significantly heavier to boot and requires JSON-serializing every message across the IPC boundary. If the heavy work is plain JavaScript computation (not a call to an external program like Python or ffmpeg), worker_threads is lighter, boots faster, and is purpose-built for this case.