04 / 17

What are the two load balancing strategies in Node.js cluster, and how do you configure them?

Node.js cluster supports two scheduling policies: SCHED_RR (Round-Robin), where the master distributes connections evenly, and SCHED_NONE, where the OS decides which worker handles each connection. You configure this via cluster.schedulingPolicy.

The scheduling policy determines how incoming connections are distributed to worker processes. Round-Robin (SCHED_RR) is the default on Linux and macOS and provides more even distribution. SCHED_NONE leaves it to the OS, which can sometimes cause uneven load distribution but reduces master-process overhead.

Configuring Scheduling Policy
Round-Robin (SCHED_RR) — Recommended
  1. 1

    Default on Linux and macOS

  2. 2

    Master process assigns connections to workers one-by-one in a cycle

  3. 3

    Provides more even and predictable load distribution

  4. 4

    Master handles distribution logic — adds slight overhead to master

OS-Handled (SCHED_NONE) — Default on Windows
  1. 1

    Default on Windows

  2. 2

    Operating system decides which worker process accepts each connection

  3. 3

    Can lead to uneven distribution — some workers may get overloaded

  4. 4

    Lower overhead on the master process

Difficulty: 5/10
Topics: cluster module, load balancing, scheduling policy

Scenario Questions

0-2 years experience
  1. 1

    You need to spawn four workers for a simple API using Node.js cluster. How would you configure the cluster to use the OS scheduler instead of the default round‑robin?

  2. 2

    If you start a cluster without setting any scheduling policy, what load‑balancing behavior should you expect on Linux versus Windows?

  3. 3

    What code changes are required to switch from round‑robin to the OS scheduler in a small script?

2-5 years experience
  1. 1

    Your service shows uneven request distribution after adding a CPU‑intensive endpoint. How would you determine if the cluster's load‑balancing strategy is the cause, and what would you change?

  2. 2

    During a deployment you notice some workers idle while others are overloaded. Explain how you would reconfigure the cluster's scheduling policy to address this and what trade‑offs you consider.

  3. 3

    You need to support both Windows and Linux environments. How would you write code that selects the appropriate scheduling policy at runtime?

5-8 years experience
  1. 1

    With 32 CPU cores handling a mix of I/O‑bound and CPU‑bound requests, discuss the pros and cons of round‑robin versus OS scheduling and how you would decide which to use for different parts of the system.

  2. 2

    Monitoring shows latency spikes when the OS scheduler is used under high load. How would you redesign the cluster configuration or add custom load balancing to mitigate this?

  3. 3

    Explain how you would implement a hybrid approach where certain routes use round‑robin and others rely on OS scheduling, and what challenges you might face.

8+ years experience
  1. 1

    Your organization is migrating a monolithic Node.js app to microservices and wants a standard for cluster load balancing across many services. What architectural guidelines would you set for choosing between round‑robin and OS scheduling, considering deployment pipelines, observability, and cross‑team maintenance?

  2. 2

    A legacy service runs on Windows where the default is OS scheduling, but you want to adopt round‑robin for consistency. How would you plan the migration, handle configuration drift, and ensure minimal downtime?

  3. 3

    Discuss the long‑term implications of hard‑coding a scheduling policy in shared libraries, and propose a strategy for making the choice configurable while preserving backward compatibility.

Follow-up Questions

  • What is the default scheduling policy on Linux versus Windows?
  • Can you change the scheduling policy after workers have already been forked?
  • How does the chosen policy affect sticky‑session handling?