Node.js
/Advanced
Clustering
Definition
A technique used to scale a Node.js application by spawning a pool of identical worker processes that share the same server port.
Explain Like I'm New
Node.js runs on a single core. If you buy a massive server with 32 CPU cores, Node will only use 1, leaving 31 cores doing absolutely nothing while your app crashes from too much traffic. Clustering tells Node to clone itself 32 times. One 'Master' clone acts as the boss, taking incoming network traffic and distributing it evenly to the 32 'Worker' clones. Now you are using 100% of your server's power.
Real World Example
Using the built-in `cluster` module or `PM2` to automatically scale an Express API across all available CPU cores on an AWS EC2 instance.
Common Use Cases
- •Vertical scaling
- •Maximizing CPU utilization
- •Zero-downtime restarts
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- How many CPU cores does standard Node.js utilize by default?
intermediate
- Do clustered worker processes share the same memory (RAM)?