Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main purpose of using a cluster in Node.js?
A cluster allows a Node.js application to use multiple CPU cores by creating child processes that share the same server port, improving performance and reliability.
Click to reveal answer
beginner
What role does a reverse proxy play in a web application setup?
A reverse proxy sits in front of web servers, forwarding client requests to them. It can handle load balancing, SSL termination, caching, and security filtering.
Click to reveal answer
intermediate
When should you choose a cluster over a reverse proxy in Node.js?
Choose a cluster when you want to maximize CPU usage within a single machine by running multiple Node.js processes to handle requests concurrently.
Click to reveal answer
intermediate
Why might you use a reverse proxy instead of a cluster for scaling?
A reverse proxy can distribute traffic across multiple servers or services, not just processes on one machine, enabling horizontal scaling and better fault tolerance.
Click to reveal answer
advanced
Can clusters and reverse proxies be used together? Explain.
Yes, clusters can be used to utilize multiple CPU cores on a single server, while a reverse proxy can distribute traffic across multiple servers running clusters, combining vertical and horizontal scaling.
Click to reveal answer
What does a Node.js cluster primarily help with?
AUsing multiple CPU cores on one machine
BDistributing traffic across multiple servers
CCaching static files
DEncrypting data between client and server
✗ Incorrect
Clusters create child processes to use multiple CPU cores on a single machine.
Which of these is NOT a typical function of a reverse proxy?
ALoad balancing
BSSL termination
CRequest filtering
DRunning multiple Node.js processes
✗ Incorrect
Running multiple Node.js processes is done by clustering, not by a reverse proxy.
If you want to scale your app across multiple servers, what should you use?
ACluster
BReverse proxy
CSingle Node.js process
DLocal caching
✗ Incorrect
A reverse proxy can distribute traffic across multiple servers for horizontal scaling.
Which setup improves CPU usage on a single machine?
ACluster only
BReverse proxy only
CNeither
DBoth cluster and reverse proxy
✗ Incorrect
Clusters create multiple processes to use all CPU cores on one machine.
What is a benefit of combining clusters with a reverse proxy?
AAutomatic database backups
BSimpler codebase
CImproved vertical and horizontal scaling
DLess network traffic
✗ Incorrect
Clusters handle multiple cores on one server (vertical scaling), reverse proxies distribute traffic across servers (horizontal scaling).
Explain the differences between a Node.js cluster and a reverse proxy and when to use each.
Think about how each helps handle more requests and where they fit in the system.
You got /5 concepts.
Describe a scenario where using both a cluster and a reverse proxy together makes sense.
Imagine a busy website running on several servers, each using clusters.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of using a cluster in a Node.js application?
easy
A. To forward HTTP requests to different servers
B. To use multiple CPU cores by creating worker processes
C. To add security features like SSL termination
D. To cache static files for faster delivery
Solution
Step 1: Understand what a cluster does in Node.js
A cluster creates multiple worker processes to use all CPU cores efficiently.
Step 2: Compare with other options
Forwarding requests and adding security are tasks of a reverse proxy, not a cluster.
Final Answer:
To use multiple CPU cores by creating worker processes -> Option B
The code calls cluster.fork() without checking if (cluster.isMaster). Both master and worker processes fork additional processes and attempt to bind to port 3000, causing port conflicts (EADDRINUSE) and crashes.
Step 2: Identify the problem
The missing if (cluster.isMaster) check before forking leads to repeated forking and server creation attempts, causing the crash.
Final Answer:
Not checking cluster.isMaster before forking -> Option C
Quick Check:
Check cluster.isMaster before fork [OK]
Hint: Always check cluster.isMaster before forking [OK]
Common Mistakes:
Calling cluster.fork() without isMaster check
Assuming fork needs a callback
Ignoring server listen port
5. You want to improve your Node.js app's performance and reliability. You decide to use both a cluster and a reverse proxy. Which setup best achieves this goal?
hard
A. Use a cluster to run multiple workers on all CPU cores, and a reverse proxy to distribute incoming requests and handle SSL
B. Use a reverse proxy to create worker processes, and a cluster to forward requests to other servers
C. Use a cluster to cache static files, and a reverse proxy to manage CPU usage
D. Use a reverse proxy to run multiple Node.js instances, and a cluster to balance traffic
Solution
Step 1: Identify cluster's role in performance
Clusters run multiple worker processes to use all CPU cores, improving performance and reliability.
Step 2: Identify reverse proxy's role in traffic and security
Only Use a cluster to run multiple workers on all CPU cores, and a reverse proxy to distribute incoming requests and handle SSL correctly assigns cluster to CPU usage and reverse proxy to traffic distribution and SSL.
Final Answer:
Use a cluster to run multiple workers on all CPU cores, and a reverse proxy to distribute incoming requests and handle SSL -> Option A