Skip to main content

Processes, Cluster & Parallelism

Node can use multiple CPU cores through worker threads or multiple processes. Process-level scaling is often orchestrated outside the application by containers, systemd, a process manager, or Kubernetes.

Options​

MechanismMemoryFailure boundaryBest for
async I/Oshared processsame processconcurrent I/O
worker threadseparate isolate, same processpartialCPU-bound JS
child processseparate processstrong process boundaryexecutables/isolation
clustermultiple Node processesprocess boundarylegacy/in-process multi-core server coordination
external replicasseparate deployment processesstrongest operational boundaryhorizontal service scaling

cluster can distribute connections across worker processes, but it should not become architecture. Modern production platforms often make separate stateless replicas clearer to deploy, observe, restart, and autoscale.

State sharing​

Memory is not shared across processes. Sessions, rate-limit counters, locks, and coordination state that must survive/scale need an external system or explicit partitioning.

Sticky sessions​

Long-lived WebSocket/session affinity may require load-balancer stickiness or shared real-time state. Sticky routing reduces flexibility and must be treated as an infrastructure contract.

Graceful restart​

start replacement
↓ readiness passes
shift traffic
↓
drain old process
↓
terminate old process

Do not restart every replica simultaneously. Rolling replacement plus readiness and shutdown budgets preserve availability.