Scaling Types
- X Axis
- Y Axis
- Z Axis
Node.js Native Modules
cluster
os
spawn
Resources and techniques
Some techniques are implemented using stack other than node.js, but the concept is more important to comprehend and implement for better performance of the application
Blogs
- Scaling Node.js Applications
- A Beginner's Guide To Scaling To 11 Million+ Users On Amazon's AWS
- Good practices for high-performance and scalable Node.js applications [Part 1/3]
- Good practices for high-performance and scalable Node.js applications [Part 2/3]
- Good practices for high-performance and scalable Node.js applications [Part 3/3]
- Scaling Up to Your First 10 Million Users
- Scaling Machine Learning from 0 to millions of users — part 1
- Scaling Machine Learning from 0 to millions of users — part 2
- https://cloudifie.com/uncategorized/scaling-from-mvp-to-10-million-users/
- Scaling on AWS Part I: A Primer
- Scaling on AWS (Part 2): > 10K Users
- Scaling on AWS (Part 3): >500K Users
- Scaling on AWS (Part 4) : > One Million Users
- Deploying and scaling Node.js on Google Kubernetes Engine with Continuous Integration
- Instagration Pt. 2: Scaling our infrastructure to multiple data centers
- Using Rust to Scale Elixir for 11 Million Concurrent Users
- How to scale a Nodejs app based on number of users
- Scaling Node.js Socket Server with Nginx and Redis
- NODE.JS scalability problems and how to solve them 🚀
- Divide and conquer: Scale your Node.js app using distributed queues
- Serving Millions of Users in Real-Time with Node.js & Microservices [Case Study]
- Scalability in NodeJS Creating a Zero-downtime cluster
- Monitoring & Vertically Scaling Node.js Applications
- Node.js scaling in highload
- How to Scale your Node.js app: Best Strategies and Built-in Tools for Scalability
- Securing and Scaling up Node.js Applications
- Scaling-out with Node Clusters
- Handling blocking operations in Node
- Interrupts and Request Memoization
Videos
- Tech Talk: Server Scaling in Node.js
- The Art of Building Node.js Projects at Scale
- Scaling Your Node.JS API Like a Boss (Part One)
- Scaling Your Node.JS API Like a Boss (Part Two)
- Scaling NodeJS - Abhinav Rastogi, Flipkart
- Abhinav Rastogi: Scaling NodeJS beyond the ordinary JSConf Iceland 2018
- Modular-services in a NodeJS monolith - Naval Saini, Flip Flop App
- Scaling Real-time Apps on Cloud Foundry Using Node.js and Redis
- Node JS - Scaling Applications - Clusters
- Node JS - Scaling Applications - Architecting Zero Downtime
- Node JS - Scaling Applications - PM2
- Using Clean Architecture for Microservice APIs in Node.js with MongoDB and Express
- Scaling NodeJS apps with N-API by Ruben Harutyunyan(Arm) JSConfAM19
- Enterprise Node.JS Apps in 2018
- Node JS - Scaling Applications
- Scaling Node.js Applications with Kubernetes and Docker - Erick Wendel, EW.IT
- Node.js at Scale with Erik Toth
- Architect for Scale - My Learnings in Node.js (A case study)
- Node.js Performance and Highly Scalable Micro-Services - Chris Bailey, IBM
- Scaling Node.js Applications with Kubernetes and Docker
- require('lx') - Scaling Node.js to 500 million Users by João Parreira
- The Node.js Event Loop: Not So Single Threaded
- Scalable Microservices with gRPC, Kubernetes, and Docker by Sandeep Dinesh, Google
- Node.js at Netflix
- Node.js: Deploying, Monitoring and Scaling
- A Million Connections...and Beyond! - Node.js at Scale
- Load Balancing with NGINX
Example Code
Cluster
Check number of CPUs
const cluster = require("cluster"); // Cluster Native Module
const cpus = require("os").cpus().length; // Number of CPUs
console.log("Number of CPUs available - ", cpus)
Full Clustering Example
const http = require("http");
const cluster = require("cluster"); // Cluster Native Module
const cpus = require("os").cpus().length; // Number of CPUs
const port = process.env.PORT || 3000;
if (cluster.isMaster) {
// Checking whether the current cluser is master or not.Boolean value is returned
console.log("Master CPU - ", process.pid);
for (var i = 0; i < cpus; i++) {
cluster.fork(); // Forking a new process from the cluster
}
cluster.on("exit", (worker) => {
console.log("Worker Process has died - " + process.pid); // Process that exited/died.
console.log("Process Remaining - " + Object.keys(cluster.workers).length); // Prints the number of running workers at any instance
console.log("Starting New Working");
console.log("Process Remaining - " + Object.keys(cluster.workers).length);
});
} else {
http
.createServer((req, res) => {
message = `Running Process: ${process.pid}`;
res.end(message);
// For Testing Purpose. Uncomment the following code to kill process by sending GET request to '/kill'
// if (req.url === "/kill") {
// process.exit();
// } else {
// console.log(process.pid);
// }
})
.listen(port);
}
Zero - Downtime Example
const http = require("http");
const cluster = require("cluster"); // Cluster Native Module
const cpus = require("os").cpus().length; // Number of CPUs
const port = process.env.PORT || 3000;
if (cluster.isMaster) {
// Checking whether the current cluser is master or not.Boolean value is returned
console.log("Master CPU - ", process.pid);
for (var i = 0; i < cpus; i++) {
cluster.fork(); // Forking a new process from the cluster
}
cluster.on("exit", (worker) => {
console.log("Worker Process has died - " + process.pid); // Process that exited/died.
console.log("Process Remaining - " + Object.keys(cluster.workers).length); // Prints the number of running workers at any instance
console.log("Starting New Working");
cluster.fork(); // Creating a new process again after the previous process exited so that max number of cpus are utilised.
console.log("Process Remaining - " + Object.keys(cluster.workers).length);
});
} else {
http
.createServer((req, res) => {
message = `Running Process: ${process.pid}`;
res.end(message);
// For Testing Purpose. Uncomment the following code to kill process by sending GET request to '/kill'
// if (req.url === "/kill") {
// process.exit();
// } else {
// console.log(process.pid);
// }
})
.listen(port);
}