0
0
Node.jsframework~20 mins

Cluster vs reverse proxy decision in Node.js - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cluster vs Reverse Proxy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Node.js Cluster vs Reverse Proxy

Which statement best explains the main difference between using Node.js cluster module and a reverse proxy like Nginx for handling multiple requests?

ACluster and reverse proxy both create multiple Node.js processes but differ in how they handle database connections.
BCluster forwards requests to external servers, while reverse proxy creates multiple Node.js processes internally.
CCluster creates multiple Node.js processes to use all CPU cores, while reverse proxy forwards requests to one or more servers without creating Node.js processes.
DCluster is used only for load balancing HTTP requests, reverse proxy is used only for caching static files.
Attempts:
2 left
💡 Hint

Think about where the work happens: inside Node.js or outside it.

component_behavior
intermediate
2:00remaining
Behavior of Node.js Cluster Module

Given the following Node.js cluster code, what will be the output when you run it on a machine with 2 CPU cores?

import cluster from 'cluster';
import os from 'os';

if (cluster.isPrimary) {
  const cpuCount = os.cpus().length;
  for (let i = 0; i < cpuCount; i++) {
    cluster.fork();
  }
  console.log(`Primary process started ${cpuCount} workers.`);
} else {
  console.log(`Worker process ${process.pid} started.`);
}
A
Primary process started 2 workers.
Worker process 1234 started.
Worker process 1235 started.
B
Primary process started 1 worker.
Worker process 1234 started.
COnly one line: Primary process started 2 workers.
DSyntaxError due to missing require statements.
Attempts:
2 left
💡 Hint

Remember that cluster.fork() creates a new worker process for each CPU core.

state_output
advanced
2:00remaining
Load Distribution with Reverse Proxy

Consider a reverse proxy setup with Nginx forwarding requests to two Node.js servers running on ports 3000 and 3001. If Nginx uses round-robin load balancing, what will be the sequence of server ports handling 4 consecutive requests?

A3000, 3000, 3001, 3001
B3000, 3001, 3000, 3001
C3001, 3000, 3001, 3000
DAll requests handled by 3000
Attempts:
2 left
💡 Hint

Round-robin means cycling through servers one by one.

📝 Syntax
advanced
2:00remaining
Correct Cluster Setup Syntax

Which option correctly sets up a Node.js cluster that logs worker IDs when they start?

Node.js
import cluster from 'cluster';
import os from 'os';

if (cluster.isPrimary) {
  const cpuCount = os.cpus().length;
  for (let i = 0; i < cpuCount; i++) {
    cluster.fork();
  }
} else {
  console.log(`Worker ${cluster.worker.id} started.`);
}
AAdd parentheses after cluster.fork like cluster.fork().
BReplace cluster.isPrimary with cluster.isMaster.
CUse cluster.worker.process.id instead of cluster.worker.id.
DCorrect as is.
Attempts:
2 left
💡 Hint

Check the current Node.js cluster API for primary process detection.

🔧 Debug
expert
2:00remaining
Debugging Reverse Proxy Connection Issue

You have a reverse proxy (Nginx) forwarding requests to a Node.js server on port 4000. The proxy returns 502 Bad Gateway errors. Which of the following is the most likely cause?

ANode.js server is not running or not listening on port 4000.
BNode.js server is running but has a syntax error in the code.
CNginx configuration has a syntax error unrelated to upstream settings.
DClient browser cache is outdated.
Attempts:
2 left
💡 Hint

502 Bad Gateway means the proxy cannot reach the backend server.