02 / 17

What is the difference between the master process and a worker process in Node.js clustering?

Difficulty: 5/10
cluster API, process management, load balancing

The master process is responsible for managing the lifecycle of worker processes — spawning, monitoring, and restarting them. Worker processes contain the actual application logic and handle incoming client requests independently.

In a clustered Node.js application, the roles of the master and worker processes are clearly separated. The master process acts as an orchestrator — it never handles HTTP requests directly. Workers are the actual application servers that process requests and respond to clients.

Master Process Responsibilities
  1. 1

    Spawn worker processes using cluster.fork()

  2. 2

    Monitor worker health and listen for exit events

  3. 3

    Restart dead workers automatically

  4. 4

    Distribute incoming connections to available workers

  5. 5

    Send configuration or messages to workers via IPC

Worker Process Responsibilities
  1. 1

    Run the actual HTTP server or application logic

  2. 2

    Handle incoming requests assigned by the master

  3. 3

    Send and receive messages to/from the master via IPC

  4. 4

    Operate independently with their own memory space

Master vs Worker Role Separation

Scenario Questions

0-2 years experience

  1. 1If you start a Node.js app with the cluster module and call `cluster.fork()` three times, what role does the original process play compared to the three new processes?
  2. 2Suppose you need to handle a CPU‑bound request in a small service. How would you decide whether to run the code in the master process or in a worker process?
  3. 3What happens if a worker process exits unexpectedly—does the master automatically restart it, and how would you observe that in logs?

2-5 years experience

  1. 1We added a new endpoint that spawns a child process inside a worker. After deployment, request latency doubled. Walk me through how the master/worker separation could be causing this.
  2. 2During a load test, the master process started using 30% CPU while workers were idle. What could be misconfigured in the clustering setup, and how would you debug it?
  3. 3Explain why you might keep certain initialization code, like a DB connection pool, in the master versus each worker, and what trade‑offs that entails.

5-8 years experience

  1. 1Our service runs on 32 cores and we need to maximize throughput while minimizing memory overhead. How would you architect the cluster—number of workers, placement of shared resources, and any modifications to the master—to achieve that?
  2. 2We need to implement graceful shutdown across a fleet of workers without dropping in‑flight requests. Describe how the master should coordinate this and what edge cases you must handle.
  3. 3If we want to hot‑swap code in workers without restarting the master, what mechanisms does the cluster module provide, and what pitfalls should we watch for at scale?

8+ years experience

  1. 1The company is migrating a monolithic Node.js app to microservices but still wants to use clustering for legacy services. How would you design the process hierarchy and deployment pipeline to allow independent scaling and rolling upgrades across teams?
  2. 2Across multiple data centers we need to coordinate master processes for global load balancing while preserving per‑region worker pools. What architectural patterns would you consider, and how would you handle state sharing and failover?
  3. 3Given security compliance requirements, some workers must run with reduced privileges. How would you modify the master‑worker model to enforce this while keeping inter‑process communication efficient?

Follow-up Questions

  • Can you show a snippet where you separate master and worker code?
  • What are the trade‑offs of loading a heavy library in the master versus each worker?
  • How would you monitor worker health and restart failures in production?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.