Node.js › Cloud & DevOps

What is a load balancer, and how does it distribute traffic across multiple Node.js application instances?

Intermediate

Answer

A load balancer sits in front of multiple instances, distributing requests according to an algorithm (round-robin, least-connections, IP-hash), improving availability (traffic routes only to healthy instances) and throughput, commonly implemented via a managed cloud load balancer or software like Nginx or HAProxy.
upstream node_app {
  server 10.0.0.1:3000;
  server 10.0.0.2:3000;
}
server {
  listen 80;
  location / { proxy_pass http://node_app; }
}
Real-world example A production API runs three instances behind an AWS ALB configured with health checks, so a crashed instance is automatically removed from rotation until it recovers.

Common follow-ups: How does the load balancer itself avoid becoming a single point of failure?;What's the difference between Layer 4 and Layer 7 load balancing, and when does it matter for a Node.js app?