03 / 17

How do you send messages between master and worker processes in a Node.js cluster?

Difficulty: 5/10
cluster IPC, message passing, worker management

Node.js cluster uses IPC (Inter-Process Communication) channels to allow message passing between the master and worker processes using worker.send() from the master and process.send() from the worker, with corresponding 'message' event listeners on both sides.

Each worker automatically has an IPC channel established with the master at the time of forking. Messages are serialized as JSON internally, so you can pass any JSON-serializable data. This is the primary way to coordinate shared state or tasks across workers since they cannot share memory directly.

Master-Worker Message Passing
Common Use Cases for IPC Messaging
  1. 1

    Sending configuration updates to all workers dynamically

  2. 2

    Aggregating metrics or counters from workers into the master

  3. 3

    Notifying the master when a worker is ready or busy

  4. 4

    Broadcasting messages to all workers from the master

  5. 5

    Coordinating graceful shutdown sequences

Scenario Questions

0-2 years experience

  1. 1You need to offload a CPU‑heavy image resize to a worker using Node's cluster module. How would you send the job description from the master to a worker and get the result back?
  2. 2If a worker calls process.send({type:'ready'}), what does the master need to do to receive that message?
  3. 3What happens if you call process.send in a script that isn’t running under a cluster?

2-5 years experience

  1. 1During a rollout you notice some workers never receive the 'shutdown' command you broadcast from the master. Walk me through how you would debug the message flow.
  2. 2You need to implement a request‑reply pattern where the master forwards HTTP requests to workers and aggregates responses. What trade‑offs do you consider when choosing between process.send and a shared memory approach?
  3. 3Explain why a worker might crash when handling a large JSON payload sent via process.send, and how you’d mitigate it.

5-8 years experience

  1. 1Your service runs on 64 cores and uses the cluster module to spawn workers. How would you design the messaging layer to avoid back‑pressure and keep throughput high?
  2. 2Discuss the implications of using process.send for transmitting binary data versus using a dedicated message queue like Redis under high load.
  3. 3If you need to hot‑swap code in workers without dropping in‑flight messages, how would you coordinate the handoff using cluster IPC?

8+ years experience

  1. 1Your organization is moving from a monolithic Node app using cluster to a microservices architecture. How would you evaluate whether to keep intra‑process messaging via process.send or replace it with an external broker?
  2. 2Across multiple teams, some services rely on cluster IPC while others use gRPC. What guidelines would you establish to maintain consistency and avoid coupling?
  3. 3Design a migration plan to phase out Node's built‑in cluster messaging in favor of a platform‑wide event bus, addressing backward compatibility and operational monitoring.

Follow-up Questions

  • What edge cases do you guard against when serializing messages?
  • How would you detect and recover from an unresponsive worker?
  • Can you compare the latency of process.send with using an external message broker?
Share

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