Don't Block the Event Loop.
The golden rule of Node.js. But what if you have to calculate a hash, resize an image, or parse a massive JSON file?
In the past, you crashed. Today, you offload it to a Worker Thread.
02. Processes vs Threads
Child Process (fork)
Entire new V8 instance. Requires huge memory overhead. Slow startup.
Worker Thread
Shares the same process memory. Lightweight. Fast message passing via ArrayBuffers.
Deep Dive: Atomics & SharedArrayBuffer
True shared memory is possible! By passing a SharedArrayBuffer to a worker, both the main thread and the worker can read/write to the same memory address instantly.
Use Atomics to prevent race conditions.
03. Easy Pattern (bree / piscina)
Don't use the raw worker_threads API unless you are building a library. Use a pool manager like Piscina.
04. The Senior Engineer's Take
Node is not Java.
Just because you can use threads doesn't mean you should make everything multithreaded. The Event Loop is still faster for I/O (DB queries, network requests).
Only use threads for CPU-bound tasks.